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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/admin/buildings_controller.rb', line 73 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 ApplicationHelper.update_buildings_details_in_property(@property.id) 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.
116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/admin/buildings_controller.rb', line 116 def destroy property_id = @building.property_id @building.destroy ApplicationHelper.update_buildings_units_details_in_property(property_id) 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.
65 |
# File 'app/controllers/admin/buildings_controller.rb', line 65 def edit; end |
#index ⇒ Object
GET /buildings GET /buildings.json Displays a list of buildings based on search criteria.
26 27 28 29 30 31 32 33 |
# File 'app/controllers/admin/buildings_controller.rb', line 26 def index @buildings = Building.search(params[:building_name], params[:property_id]).page params[:page] if request.xhr? render action: :index ,layout: false else render action: :index, layout: true end end |
#new ⇒ Object
GET /buildings/new Displays a form for creating a new building.
58 59 60 61 |
# File 'app/controllers/admin/buildings_controller.rb', line 58 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/admin/buildings_controller.rb', line 40 def show @property = @building.property units = @building.units.to_a @units = ApplicationHelper.custom_sort(units, :unit_name) respond_to do |format| format.xlsx do response.headers[ 'Content-Disposition' ] = "attachment; filename='Units.xlsx'" end format.html do render action: :show 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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/admin/buildings_controller.rb', line 95 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 |