Sha256: eadc42a3c1a01a437b7db1c75114fa7ea2d9ec3978b330dce5d070bdecbb8353

Contents?: true

Size: 1.55 KB

Versions: 28

Compression:

Stored size: 1.55 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
        )
      end

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.15 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.14 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.13 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.12 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.11 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.9 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.8 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.7 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.5 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.4 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.3 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.2 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.1 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.0.pre.rc7 app/controllers/renalware/hospitals/units_controller.rb