Class: Renalware::Patients::BookmarksController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- Renalware::Patients::BookmarksController
- Includes:
- Concerns::Pageable
- 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
22 23 24 25 26 27 28 |
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 22 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
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 31 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
10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 10 def index search = BookmarksQuery.new( default_relation: Patients.cast_user(current_user).bookmarks, params: params[:q] ).search bookmarks = search.result.page(page).per(per_page) bookmarks render locals: { bookmarks: bookmarks, search: search } end |