Sha256: b4723c539c8de27029c8c9e8f9339e4002c9cbeda95b3cb906bf66018334276f

Contents?: true

Size: 1014 Bytes

Versions: 2

Compression:

Stored size: 1014 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/low_clearance"

module Renalware
  module LowClearance
    class ProfilesController < BaseController
      def edit
        render_edit(find_and_authorize_profile)
      end

      def update
        profile = find_and_authorize_profile
        if profile.update_by(current_user, profile_params)
          redirect_to patient_low_clearance_dashboard_path,
                      notice: success_msg_for("profile")
        else
          flash.now[:error] = failed_msg_for("profile")
          render_edit(profile)
        end
      end

      private

      def find_and_authorize_profile
        (patient.profile || patient.build_profile).tap do |profile|
          authorize profile
        end
      end

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

      def profile_params
        params.require(:low_clearance_profile).permit(:referrer_id, document: {})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/low_clearance/profiles_controller.rb
renalware-core-2.1.0 app/controllers/renalware/low_clearance/profiles_controller.rb