Class: Admin::UnitsController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::UnitsController
- Defined in:
- app/controllers/admin/units_controller.rb
Overview
Controller for managing units.
Instance Method Summary collapse
-
#create ⇒ Object
POST /units POST /units.json Creates a new unit.
-
#destroy ⇒ Object
DELETE /units/1 DELETE /units/1.json Deletes an existing unit.
-
#edit ⇒ Object
GET /units/1/edit Displays a form for editing a unit.
-
#index ⇒ Object
GET /units GET /units.json Displays a list of units.
-
#new ⇒ Object
GET /units/new Displays a form for creating a new unit.
-
#show ⇒ Object
GET /units/1 GET /units/1.json Displays the details of a specific unit.
-
#update ⇒ Object
PATCH/PUT /units/1 PATCH/PUT /units/1.json Updates an existing unit.
Instance Method Details
#create ⇒ Object
POST /units POST /units.json Creates a new unit.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/admin/units_controller.rb', line 39 def create @unit = Unit.new(unit_params.merge(properties: properties_params, created_by_id: current_user.id)) respond_to do |format| if @unit.save @building = Building.find(@unit.building_id) format.html { redirect_to admin_building_path(@building), notice: 'Unit was successfully created.' } format.json { render :show, status: :created, location: @unit } else format.html { render :new } format.json { render json: @unit.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /units/1 DELETE /units/1.json Deletes an existing unit.
72 73 74 75 76 77 78 79 |
# File 'app/controllers/admin/units_controller.rb', line 72 def destroy building_id = @unit.building_id @unit.destroy respond_to do |format| format.html { redirect_to admin_building_path(Building.find(building_id)), notice: 'Unit was successfully destroyed.' } format.json { head :no_content } end end |
#edit ⇒ Object
GET /units/1/edit Displays a form for editing a unit.
34 |
# File 'app/controllers/admin/units_controller.rb', line 34 def edit; end |
#index ⇒ Object
GET /units GET /units.json Displays a list of units.
11 12 13 14 15 |
# File 'app/controllers/admin/units_controller.rb', line 11 def index @units = Unit.search(params[:property_id]).page params[:page] render action: :index, layout: request.xhr?.nil? end |
#new ⇒ Object
GET /units/new Displays a form for creating a new unit.
24 25 26 27 28 29 30 |
# File 'app/controllers/admin/units_controller.rb', line 24 def new @unit = Unit.new if params[:unit] @property = Property.find(params[:unit][:property_id]) @building = Building.find(params[:unit][:building_id]) end end |
#show ⇒ Object
GET /units/1 GET /units/1.json Displays the details of a specific unit.
20 |
# File 'app/controllers/admin/units_controller.rb', line 20 def show; end |
#update ⇒ Object
PATCH/PUT /units/1 PATCH/PUT /units/1.json Updates an existing unit.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/admin/units_controller.rb', line 56 def update respond_to do |format| if @unit.update(unit_params.merge(properties: properties_params, updated_by_id: current_user.id)) @building = Building.find(@unit.building_id) format.html { redirect_to admin_building_path(@building), notice: 'Unit was successfully updated.' } format.json { render :show, status: :ok, location: @unit } else format.html { render :edit } format.json { render json: @unit.errors, status: :unprocessable_entity } end end end |