Class: Renalware::Patients::BookmarksController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- Renalware::Patients::BookmarksController
- Defined in:
- app/controllers/renalware/patients/bookmarks_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
idempotent.
-
#destroy ⇒ Object
idempotent.
-
#index ⇒ Object
Display the user’s bookmarks.
Methods inherited from BaseController
Instance Method Details
#create ⇒ Object
idempotent
19 20 21 22 23 24 25 |
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 19 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 |
#destroy ⇒ Object
idempotent
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 28 def destroy bookmark = user.bookmarks.find_by(id: params[:id]) patient = bookmark&.patient if bookmark.present? bookmark bookmark.destroy else end fallback_location = patient.presence || root_path redirect_back(fallback_location: patient_path(fallback_location), notice: success_msg_for("bookmark")) end |
#index ⇒ Object
Display the user’s bookmarks
9 10 11 12 13 14 15 16 |
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 9 def index bookmarks = Patients.cast_user(current_user) .bookmarks .ordered .includes(patient: [current_modality: :description]) bookmarks render locals: { bookmarks: bookmarks } end |