Sha256: 55d3041f8e4b91826e09b181dc71483bf763865ad62782e2a47e1f15ba44f518

Contents?: true

Size: 1.97 KB

Versions: 128

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd/base_controller"

module Renalware
  module HD
    class DialysatesController < HD::BaseController
      def index
        dialysates = Dialysate.all
        authorize dialysates
        render locals: { dialysates: dialysates }
      end

      def new
        dialysate = Dialysate.new
        authorize dialysate
        render_new(dialysate)
      end

      def create
        dialysate = Dialysate.new(dialysate_params)
        authorize dialysate

        if dialysate.save
          redirect_to hd_dialysates_path, notice: success_msg_for("dialysate")
        else
          flash.now[:error] = failed_msg_for("dialysate")
          render_new(dialysate)
        end
      end

      def edit
        render_edit(find_and_authorize_dialysate)
      end

      def update
        dialysate = find_and_authorize_dialysate
        if dialysate.update(dialysate_params)
          redirect_to hd_dialysates_path, notice: success_msg_for("dialysate")
        else
          flash.now[:error] = failed_msg_for("dialysate")
          render_edit(dialysate)
        end
      end

      def destroy
        find_and_authorize_dialysate.destroy!
        redirect_to hd_dialysates_path, notice: success_msg_for("dialysate")
      end

      private

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

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

      def find_and_authorize_dialysate
        Dialysate.find(params[:id]).tap { |dialysate| authorize(dialysate) }
      end

      def dialysate_params
        params
          .require(:dialysate)
          .permit(
            :name, :description,
            :sodium_content, :sodium_content_uom,
            :bicarbonate_content, :bicarbonate_content_uom,
            :calcium_content, :calcium_content_uom,
            :potassium_content, :potassium_content_uom
          )
      end
    end
  end
end

Version data entries

128 entries across 128 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.1.0 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.167 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.166 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.165 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.164 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.163 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.162 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.161 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.160 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.159 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.158 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.157 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.156 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.155 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.153 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.152 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.151 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.149 app/controllers/renalware/hd/dialysates_controller.rb
renalware-core-2.0.148 app/controllers/renalware/hd/dialysates_controller.rb