Class: Renalware::Hospitals::WardsController

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

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/renalware/hospitals/wards_controller.rb', line 27

def create
  ward = unit.wards.build(ward_params)
  authorize ward
  if ward.save
    redirect_to hospitals_unit_wards_path(unit), notice: success_msg_for(:ward)
  else
    render_new(ward)
  end
end

#destroyObject



50
51
52
53
# File 'app/controllers/renalware/hospitals/wards_controller.rb', line 50

def destroy
  find_an_authorise_ward.destroy!
  redirect_to hospitals_unit_wards_path(unit), notice: success_msg_for(:ward)
end

#editObject



37
38
39
# File 'app/controllers/renalware/hospitals/wards_controller.rb', line 37

def edit
  render_edit(find_an_authorise_ward)
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/renalware/hospitals/wards_controller.rb', line 8

def index
  authorize Ward, :index?
  wards = Ward.where(hospital_unit_id: unit.id).order(name: :asc)
  respond_to do |format|
    format.json do
      render json: wards.select(:id, :name).to_json
    end
    format.html do
      render locals: { unit: unit, wards: wards }
    end
  end
end

#newObject



21
22
23
24
25
# File 'app/controllers/renalware/hospitals/wards_controller.rb', line 21

def new
  ward = unit.wards.build
  authorize ward
  render_new(ward)
end

#updateObject



41
42
43
44
45
46
47
48
# File 'app/controllers/renalware/hospitals/wards_controller.rb', line 41

def update
  ward = find_an_authorise_ward
  if ward.update(ward_params)
    redirect_to hospitals_unit_wards_path(unit), notice: success_msg_for(:ward)
  else
    render_edit(find_an_authorise_ward)
  end
end