Class: Renalware::Letters::Mailshots::MailshotsController

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

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/renalware/letters/mailshots/mailshots_controller.rb', line 23

def create
  mailshot = Mailshot.new(mailshot_params)
  authorize mailshot, :create?
  mailshot.letters_count = mailshot.recipient_patients.length
  mailshot.status = "queued"

  if mailshot.save_by(current_user)
    CreateMailshotLettersJob.perform_later(mailshot)
    redirect_to letters_mailshots_path, notice: "Mailshot queued for background processing"
  else
    render_new(mailshot)
  end
end

#indexObject



11
12
13
14
15
# File 'app/controllers/renalware/letters/mailshots/mailshots_controller.rb', line 11

def index
  pagy, mailshots = pagy(Mailshot.includes(:author).order(created_at: :desc))
  authorize mailshots
  render locals: { mailshots: mailshots, pagy: pagy }
end

#newObject



17
18
19
20
21
# File 'app/controllers/renalware/letters/mailshots/mailshots_controller.rb', line 17

def new
  mailshot = Mailshot.new
  authorize mailshot
  render_new(mailshot)
end