Class: Renalware::Letters::Mailshots::PatientPreviewsController

Inherits:
BaseController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/renalware/letters/mailshots/patient_previews_controller.rb

Overview

Called via ajax from the new mailshot form, and responsible for taking the SQL view the user has chosen as the mailshot datasource, and returning a list of patients that the user can see and check before going on to create the mailshot.

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Methods inherited from BaseController

#patient

Instance Method Details

#indexObject

Note we use data-remote as we want the table where the previewed patients are displayed to have pagination links that work via ajax and do not refresh the page.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/renalware/letters/mailshots/patient_previews_controller.rb', line 16

def index
  authorize Patient, :index?
  pagy, patients = pagy(
    Mailshot.new(sql_view_name: sql_view_name).recipient_patients,
    link_extra: "data-remote='true'"
  )
  render locals: {
    patients: patients,
    pagy: pagy,
    datasource: DataSource.find_by(viewname: sql_view_name)
  }
end