Class: Renalware::Patients::BookmarksController

Inherits:
BaseController show all
Defined in:
app/controllers/renalware/patients/bookmarks_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject

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

#destroyObject

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?
    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

#indexObject

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])
  authorize bookmarks
  render locals: { bookmarks: bookmarks }
end