Class: Admin::InspectableItemsController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::InspectableItemsController
- Defined in:
- app/controllers/admin/inspectable_items_controller.rb
Overview
Controller for managing inspectable items.
Instance Method Summary collapse
-
#create ⇒ Object
POST /inspectable_items POST /inspectable_items.json Creates a new inspectable item.
-
#destroy ⇒ Object
DELETE /inspectable_items/1 DELETE /inspectable_items/1.json Deletes an existing inspectable item.
-
#edit ⇒ Object
GET /inspectable_items/1/edit Displays a form for editing an inspectable item.
-
#index ⇒ Object
GET /inspectable_items GET /inspectable_items.json Displays a list of inspectable items.
-
#inspectable_items_search ⇒ Object
GET /inspectable_items/inspectable_items_search Searches for inspectable items based on item name.
-
#new ⇒ Object
GET /inspectable_items/new Displays a form for creating a new inspectable item.
-
#show ⇒ Object
GET /inspectable_items/1 GET /inspectable_items/1.json Displays the details of a specific inspectable item.
-
#update ⇒ Object
PATCH/PUT /inspectable_items/1 PATCH/PUT /inspectable_items/1.json Updates an existing inspectable item.
Instance Method Details
#create ⇒ Object
POST /inspectable_items POST /inspectable_items.json Creates a new inspectable item.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 52 def create params = inspectable_item_params params[:created_by_id] = current_user.id params[:updated_by_id] = current_user.id properties = { 'item_weight' => params['item_weight'] } params[:properties] = properties params.delete(:item_weight) @inspectable_item = InspectableItem.new(params) respond_to do |format| if @inspectable_item.save format.html { redirect_to admin_inspectable_items_path, notice: 'Inspectable item was successfully created.' } format.json { render :show, status: :created, location: @inspectable_item } else format.html { render :new } format.json { render json: @inspectable_item.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /inspectable_items/1 DELETE /inspectable_items/1.json Deletes an existing inspectable item.
101 102 103 104 105 106 107 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 101 def destroy @inspectable_item.delete respond_to do |format| format.html { redirect_to admin_inspectable_items_url, notice: 'Inspectable item was successfully destroyed.' } format.json { head :no_content } end end |
#edit ⇒ Object
GET /inspectable_items/1/edit Displays a form for editing an inspectable item.
45 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 45 def edit; end |
#index ⇒ Object
GET /inspectable_items GET /inspectable_items.json Displays a list of inspectable items.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 11 def index respond_to do |format| format.xlsx do @inspectable_items = InspectableItem.search(params[:area], params[:item_name], params[:item_code]) response.headers[ 'Content-Disposition' ] = "attachment; filename='items.xlsx'" end format.html do @inspectable_items = InspectableItem.search(params[:inspection_area_id], params[:item_name], params[:item_code]).page params[:page] if request.xhr? render action: :index ,layout: false else render action: :index, layout: true end end end end |
#inspectable_items_search ⇒ Object
GET /inspectable_items/inspectable_items_search Searches for inspectable items based on item name.
113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 113 def inspectable_items_search item_name = params[:item_name] @inspectable_items = InspectableItem.where('title ILIKE ?', "%#{item_name}%").order(updated_at: :desc) items = @inspectable_items.map do |item| { id: item.id, title: item.title, area_name: item.inspection_area.area_name } end render json: items end |
#new ⇒ Object
GET /inspectable_items/new Displays a form for creating a new inspectable item.
39 40 41 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 39 def new @inspectable_item = InspectableItem.new end |
#show ⇒ Object
GET /inspectable_items/1 GET /inspectable_items/1.json Displays the details of a specific inspectable item.
35 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 35 def show; end |
#update ⇒ Object
PATCH/PUT /inspectable_items/1 PATCH/PUT /inspectable_items/1.json Updates an existing inspectable item.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/admin/inspectable_items_controller.rb', line 79 def update params = inspectable_item_params params[:updated_by_id] = current_user.id properties = { 'item_weight' => params['item_weight'] } params[:properties] = properties params.delete(:item_weight) respond_to do |format| if @inspectable_item.update(params) format.html { redirect_to admin_inspectable_items_path, notice: 'Inspectable item was successfully updated.' } format.json { render :show, status: :ok, location: @inspectable_item } else format.html { render :edit } format.json { render json: @inspectable_item.errors, status: :unprocessable_entity } end end end |