Class: Renalware::Hospitals::UnitsController

Inherits:
BaseController show all
Defined in:
app/controllers/renalware/hospitals/units_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/renalware/hospitals/units_controller.rb', line 14

def create
  hospital_unit = Unit.new(hospital_unit_params)
  authorize hospital_unit

  if hospital_unit.save
    redirect_to hospitals_units_path, notice: success_msg_for("hospital unit")
  else
    flash.now[:error] = failed_msg_for("hospital unit")
    render_new(hospital_unit)
  end
end

#destroyObject



46
47
48
49
50
# File 'app/controllers/renalware/hospitals/units_controller.rb', line 46

def destroy
  hospital_unit = find_and_authorize_hospital_unit
  hospital_unit.destroy!
  redirect_to hospitals_units_path, notice: success_msg_for("hospital unit")
end

#editObject



32
33
34
# File 'app/controllers/renalware/hospitals/units_controller.rb', line 32

def edit
  render_edit(find_and_authorize_hospital_unit)
end

#indexObject



26
27
28
29
30
# File 'app/controllers/renalware/hospitals/units_controller.rb', line 26

def index
  hospital_units = Unit.includes(:hospital_centre).all
  authorize hospital_units
  render locals: { hospital_units: hospital_units }
end

#newObject



8
9
10
11
12
# File 'app/controllers/renalware/hospitals/units_controller.rb', line 8

def new
  hospital_unit = Unit.new
  authorize hospital_unit
  render_new(hospital_unit)
end

#updateObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/renalware/hospitals/units_controller.rb', line 36

def update
  hospital_unit = find_and_authorize_hospital_unit
  if hospital_unit.update(hospital_unit_params)
    redirect_to hospitals_units_path, notice: success_msg_for("hospital unit")
  else
    flash.now[:error] = failed_msg_for("hospital unit")
    render_edit(hospital_unit)
  end
end