Sha256: a85e2d47f439fbeea3fde1991f5e31cae45fd0a2921651a35c7848dabea89a54

Contents?: true

Size: 1.13 KB

Versions: 26

Compression:

Stored size: 1.13 KB

Contents

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

      # idempotent
      def create
        Bookmark.find_or_create_by!(user: user, patient: patient) do |bookmark|
          bookmark.assign_attributes(bookmark_params)
        end
        redirect_back(fallback_location: patient_path(patient),
                      notice: success_msg_for("bookmark"))
      end

      # idempotent
      def destroy
        bookmark = user.bookmarks.find_by(id: params[:id])
        patient = bookmark&.patient
        if bookmark.present?
          authorize bookmark
          bookmark.destroy
        else
          skip_authorization
        end
        fallback_location = patient.presence || root_path
        redirect_back(fallback_location: patient_path(fallback_location),
                      notice: success_msg_for("bookmark"))
      end

      private

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

      def bookmark_params
        params.require(:patients_bookmark).permit(:notes, :urgent, :tags)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.15 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.14 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.13 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.12 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.11 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.9 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.8 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.7 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.5 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.4 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.3 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.2 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.1 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.0 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/patients/bookmarks_controller.rb