Sha256: bbc9d02dce6ba03cf954c186dc94cdf6247c79e5dee356595960cf9e90800378

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 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[: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[: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, :is_hd_site, :hospital_centre_id
        )
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta4 app/controllers/renalware/hospitals/units_controller.rb