Class: Admin::BuildingsController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::BuildingsController
- Defined in:
- app/controllers/admin/buildings_controller.rb
Overview
Controller for managing buildings.
Instance Method Summary collapse
-
#create ⇒ HTML/JSON
POST /buildings POST /buildings.json Creates a new building based on the provided parameters.
-
#destroy ⇒ HTML/JSON
DELETE /buildings/1 DELETE /buildings/1.json Deletes an existing building.
-
#edit ⇒ Object
GET /buildings/1/edit Displays a form for editing a building.
-
#index ⇒ Object
GET /buildings GET /buildings.json Displays a list of buildings based on search criteria.
-
#new ⇒ Object
GET /buildings/new Displays a form for creating a new building.
-
#show ⇒ HTML
GET /buildings/1 GET /buildings/1.json Displays the details of a specific building.
-
#units ⇒ JSON
GET /buildings/units GET /buildings/units.json Returns the units of a building by its ID in JSON format.
-
#update ⇒ HTML/JSON
PATCH/PUT /buildings/1 PATCH/PUT /buildings/1.json Updates an existing building based on the provided parameters.
Instance Method Details
#create ⇒ HTML/JSON
POST /buildings POST /buildings.json Creates a new building based on the provided parameters.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/admin/buildings_controller.rb', line 68 def create params = building_params.merge(properties: properties_params, created_by_id: current_user.id) @building = Building.new(params) respond_to do |format| @property = Property.find_by_id(params[:property_id]) if @building.save format.html { redirect_to admin_property_path(@property), notice: 'Building was successfully created.' } format.json { render :show, status: :created, location: @building } else format.html { render :new } format.json { render json: @building.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ HTML/JSON
DELETE /buildings/1 DELETE /buildings/1.json Deletes an existing building.
110 111 112 113 114 115 116 117 |
# File 'app/controllers/admin/buildings_controller.rb', line 110 def destroy property_id = @building.property_id @building.destroy respond_to do |format| format.html { redirect_to admin_property_url(Property.find(property_id)), notice: 'Building was successfully destroyed.' } format.json { head :no_content } end end |
#edit ⇒ Object
GET /buildings/1/edit Displays a form for editing a building.
60 |
# File 'app/controllers/admin/buildings_controller.rb', line 60 def edit; end |
#index ⇒ Object
GET /buildings GET /buildings.json Displays a list of buildings based on search criteria.
26 27 28 29 |
# File 'app/controllers/admin/buildings_controller.rb', line 26 def index @buildings = Building.search(params[:building_name], params[:property_id]).page params[:page] render action: :index, layout: request.xhr?.nil? end |
#new ⇒ Object
GET /buildings/new Displays a form for creating a new building.
53 54 55 56 |
# File 'app/controllers/admin/buildings_controller.rb', line 53 def new @building = Building.new @property = Property.find(params[:building][:property_id]) if params[:building] && params[:building][:property_id] end |
#show ⇒ HTML
GET /buildings/1 GET /buildings/1.json Displays the details of a specific building.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/admin/buildings_controller.rb', line 36 def show @property = @building.property @units = @building.units respond_to do |format| format.xlsx do response.headers[ 'Content-Disposition' ] = "attachment; filename='Units.xlsx'" end format.html do render action: :show, layout: request.xhr?.nil? end end end |
#units ⇒ JSON
GET /buildings/units GET /buildings/units.json Returns the units of a building by its ID in JSON format.
14 15 16 17 18 |
# File 'app/controllers/admin/buildings_controller.rb', line 14 def units building_id = params[:building_id] @units = Building.find_by_old_id(building_id).units render json: @units end |
#update ⇒ HTML/JSON
PATCH/PUT /buildings/1 PATCH/PUT /buildings/1.json Updates an existing building based on the provided parameters.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/admin/buildings_controller.rb', line 89 def update respond_to do |format| # return render json: building_params[:construction_date] params = building_params.merge(properties: properties_params, updated_by_id: current_user.id) @property = Property.find_by_id(@building.property_id) if @building.update(params) format.html { redirect_to admin_property_path(@property), notice: 'Building was successfully updated.' } format.json { render :show, status: :ok, location: @building } else format.html { render :edit } format.json { render json: @building.errors, status: :unprocessable_entity } end end end |