Class: HardwaresController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- HardwaresController
- Defined in:
- app/controllers/hardwares_controller.rb
Overview
The hardware controller.
Instance Method Summary (collapse)
-
- (Object) create
POST /hardwares POST /hardwares.json.
-
- (Object) destroy
DELETE /hardwares/1 DELETE /hardwares/1.json.
-
- (Object) edit
GET /hardwares/1/edit.
-
- (Object) index
GET /hardwares GET /hardwares.json.
-
- (Object) new
GET /hardwares/new.
-
- (Object) show
GET /hardwares/1 GET /hardwares/1.json.
-
- (Object) update
PATCH/PUT /hardwares/1 PATCH/PUT /hardwares/1.json.
Instance Method Details
- (Object) create
POST /hardwares POST /hardwares.json
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/hardwares_controller.rb', line 33 def create #TODO: if hardware type is iBeacon, major id and minor id is required @hardware_types = HardwaresHelper.supported_hardware_types_with_names @tag_id = params['hardware']['tag_id'] @hardware = Hardware.new(hardware_params) @hardware.identifier = @hardware.identifier.upcase result = @hardware.save if result unless @tag_id.nil? tag = Tag.find_by_id(@tag_id) tag.hardwares << @hardware end end respond_to do |format| if result format.html { redirect_to tag_path(@tag_id), notice: 'Hardware was successfully created.' } format.json { render :show, status: :created, location: @hardware } else format.html { render :new } format.json { render json: @hardware.errors, status: :unprocessable_entity } end end end |
- (Object) destroy
DELETE /hardwares/1 DELETE /hardwares/1.json
81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/hardwares_controller.rb', line 81 def destroy tag_id = params['tag_id'] @hardware.destroy respond_to do |format| format.html { redirect_to tag_path(tag_id), notice: 'Hardware was successfully destroyed.' } format.json { head :no_content } end end |
- (Object) edit
GET /hardwares/1/edit
26 27 28 29 |
# File 'app/controllers/hardwares_controller.rb', line 26 def edit @tag_id = params['tag_id'] @hardware_types = HardwaresHelper.supported_hardware_types_with_names end |
- (Object) index
GET /hardwares GET /hardwares.json
9 10 11 |
# File 'app/controllers/hardwares_controller.rb', line 9 def index # @hardwares = Hardware.all end |
- (Object) new
GET /hardwares/new
19 20 21 22 23 |
# File 'app/controllers/hardwares_controller.rb', line 19 def new @hardware = Hardware.new @tag_id = params['tag_id'] @hardware_types = HardwaresHelper.supported_hardware_types_with_names end |
- (Object) show
GET /hardwares/1 GET /hardwares/1.json
15 16 |
# File 'app/controllers/hardwares_controller.rb', line 15 def show end |
- (Object) update
PATCH/PUT /hardwares/1 PATCH/PUT /hardwares/1.json
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/hardwares_controller.rb', line 65 def update @tag_id = params['hardware']['tag_id'] respond_to do |format| if @hardware.update(hardware_params) format.html { redirect_to tag_path(@tag_id), notice: 'Hardware was successfully updated.' } format.json { render :show, status: :ok, location: @hardware } else format.html { render :edit } format.json { render json: @hardware.errors, status: :unprocessable_entity } end end end |