Class: RisksController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/risks_controller.rb

Overview

This controller manage the views refering to Risk model

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin_in!, #doctor_in!, #powered_in!, #secretary_in!, #translate_errors

Instance Method Details

#createObject

POST /risks

try to make a new category Risk

  • set @risk with new Risk with #risk_params as params

Returns:

  • (Object)

    if @risk is created render /risks/index otherwise render /risk/edit



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

#destroyObject

DELETE /risks/:id

Destroy a Risk category

  • set @risk with #set_risk method

  • try to destroy @risk

Returns:

  • (Object)

    render



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

#editObject

GET /risks/:id/edit

render the form for update a category Risk

  • set @risk with #set_risk method

Returns:

  • (Object)

    render risk/edit



42
43
44
# File 'app/controllers/risks_controller.rb', line 42

def edit
  # empty
end

#indexObject

GET /risks

Show a list of Risk

  • set @risks with #risks

Returns:

  • (Object)

    render risks/index



17
# File 'app/controllers/risks_controller.rb', line 17

def index; end

#listObject

GET /audits/list

render the list the all Audit

  • set @pagy, @audits for the @users pagination

Returns:

  • (Object)

    render users/index



24
25
26
# File 'app/controllers/risks_controller.rb', line 24

def list
  @pagy, @risks = pagy(risks, link_extra: "data-turbo-frame='risks'")
end

#newObject

GET /risks/new

render the form for make a new category Risk

  • set @risk as new Risk

Returns:

  • (Object)

    render risk/new



33
34
35
# File 'app/controllers/risks_controller.rb', line 33

def new
  @risk = Risk.new
end

#updateObject

PATCH/PUT /risks/:id/

try to update a category Risk

  • set @risk with #set_risk method

  • update @risk with #risk_params as param

Returns:

  • (Object)

    if @risk is updated render risks/index otherwise risks/edit



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