Sha256: 5e4a3c7939c7bdb10e61942ab2235a46182ea458e1bd5ae298678a4e671306f4

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

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

      # idempotent
      def create
        Worry.find_or_create_by!(patient: patient) do |worry|
          worry.by = user
        end
        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 user
        @user ||= Renalware::Patients.cast_user(current_user)
      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/patients/worry_controller.rb