Sha256: 0d2e32670db449df84e2b579006b5f0bd22be959336c5a44b1b8c625cb774e84

Contents?: true

Size: 1.13 KB

Versions: 25

Compression:

Stored size: 1.13 KB

Contents

module Renalware
  module Patients
    class WorryController < BaseController
      before_action :load_patient, only: :create

      # idempotent
      def create
        worry = Worry.find_or_create_by!(patient: patient) do |wor|
          wor.by = user
        end
        update_worry_notes_if_supplied(worry)
        redirect_back(fallback_location: patient_path(patient),
                      notice: t(".success", patient: patient))
      end

      # idempotent
      def destroy
        if (worry = patient.worry)
          authorize worry
          worry.destroy!
        else
          skip_authorization
        end
        redirect_back(fallback_location: patient_path(patient),
                      notice: t(".success", patient: patient))
      end

      private

      def update_worry_notes_if_supplied(worry)
        if worry_params[:notes].present?
          worry.update_attributes(worry_params.merge!(by: current_user))
        end
      end

      def user
        @user ||= Renalware::Patients.cast_user(current_user)
      end

      def worry_params
        params.require(:patients_worry).permit(:notes)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
renalware-core-2.0.5 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.4 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.3 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.2 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.1 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc7 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc6 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc5 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc4 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc3 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.rc1 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.beta12 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.beta11 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.0.pre.beta10 app/controllers/renalware/patients/worry_controller.rb