Sha256: 1767ba12657a90920f012620aa7b475d3d8254c8ded639ef0171363ea0933be3

Contents?: true

Size: 1.99 KB

Versions: 64

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hospitals"

module Renalware
  module Hospitals
    class UnitsController < BaseController
      def new
        hospital_unit = Unit.new
        authorize hospital_unit
        render_new(hospital_unit)
      end

      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

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

      def edit
        render_edit(find_and_authorize_hospital_unit)
      end

      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

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

      private

      def render_new(hospital_unit)
        render :new, locals: { hospital_unit: hospital_unit }
      end

      def render_edit(hospital_unit)
        render :edit, locals: { hospital_unit: hospital_unit }
      end

      def find_and_authorize_hospital_unit
        hospital_unit = Unit.find(params[:id])
        authorize hospital_unit
        hospital_unit
      end

      def hospital_unit_params
        params.require(:hospitals_unit).permit(
          :name, :unit_code, :renal_registry_code, :unit_type, :hospital_centre_id, :is_hd_site
        )
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
renalware-core-2.0.147 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.146 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.145 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.144 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.143 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.142 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.141 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.140 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.139 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.138 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.137 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.136 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.135 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.134 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.133 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.132 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.131 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.130 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.129 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.128 app/controllers/renalware/hospitals/units_controller.rb