Class: RisksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RisksController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/risks_controller.rb
Overview
This controller manage the views refering to Risk model
-
before_action :ApplicationController#powered_in!
-
before_action :set_risk, only: [:edit, :update, :destroy]
Instance Method Summary collapse
-
#create ⇒ Object
POST /risks.
-
#destroy ⇒ Object
DELETE /risks/:id.
-
#edit ⇒ Object
GET /risks/:id/edit.
-
#index ⇒ Object
GET /risks.
-
#list ⇒ Object
GET /audits/list.
-
#new ⇒ Object
GET /risks/new.
-
#update ⇒ Object
PATCH/PUT /risks/:id/.
Methods inherited from ApplicationController
#admin_in!, #doctor_in!, #powered_in!, #secretary_in!, #translate_errors
Instance Method Details
#create ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/risks_controller.rb', line 52 def create @risk = Risk.new(risk_params) if @risk.save risks flash.now[:success] = 'Creazione avvenuta con successo' render :index, status: :ok else flash.now[:error] = 'Si è verificato un errore durante la creazione' render :edit, status: :error end end |
#destroy ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/risks_controller.rb', line 87 def destroy if @risk.destroy flash.now[:success] = 'Cancellazione avvenuta con successo' else flash.now[:error] = 'Si è verificato un errore durante la cancellazione' end render turbo_stream: [ turbo_stream.replace(:flashes, partial: "flashes"), turbo_stream.remove("risk_#{@risk.id}") ] end |
#edit ⇒ Object
42 43 44 |
# File 'app/controllers/risks_controller.rb', line 42 def edit # empty end |
#index ⇒ Object
17 |
# File 'app/controllers/risks_controller.rb', line 17 def index; end |
#list ⇒ Object
24 25 26 |
# File 'app/controllers/risks_controller.rb', line 24 def list @pagy, @risks = pagy(risks, link_extra: "data-turbo-frame='risks'") end |
#new ⇒ Object
33 34 35 |
# File 'app/controllers/risks_controller.rb', line 33 def new @risk = Risk.new end |
#update ⇒ Object
PATCH/PUT /risks/:id/
try to update a category Risk
-
set @risk with #set_risk method
-
update @risk with #risk_params as param
70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/risks_controller.rb', line 70 def update if @risk.update(risk_params) risks flash.now[:success] = 'Modifica avvenuta con successo' render :index, status: :ok else flash.now[:error] = 'Si è verificato un errore durante la modifica' render :edit, status: :error end end |