Sha256: 38afd51dad6d7640edb7168c932b7477f4129e3e97f9f996560752e53484159e

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

require_dependency "renalware/hospitals"

module Renalware
  module Hospitals
    class UnitsController < BaseController
      before_action :load_hospital_unit, only: [:edit, :update]

      def new
        @hospital_unit = Unit.new
        authorize @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: t(".success", model_name: "hospital unit")
        else
          flash.now[:error] = t(".failed", model_name: "hospital unit")
          render :new
        end
      end

      def index
        @hospital_units = Unit.all
        authorize @hospital_units
      end

      def update
        if @hospital_unit.update(hospital_unit_params)
          redirect_to hospitals_units_path,
            notice: t(".success", model_name: "hospital unit")
        else
          flash.now[:error] = t(".failed", model_name: "hospital unit")
          render :edit
        end
      end

      def destroy
        authorize Unit.destroy(params[:id])
        redirect_to hospitals_units_path,
          notice: t(".success", model_name: "hospital unit")
      end

      private

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta9 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.beta8 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.beta7 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.beta6 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.beta5 app/controllers/renalware/hospitals/units_controller.rb