Define a worker process and endpoint to send invitations PDF via email #293
@ -26,6 +26,12 @@ class InvitationsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def email
|
||||
AdminMailer.with(wedding_id: ActsAsTenant.current_tenant.id).invitations_pdf_email.deliver_later
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
def sheet; end
|
||||
|
||||
def show
|
||||
|
@ -5,14 +5,41 @@
|
||||
class AdminMailer < ApplicationMailer
|
||||
def attendance_change_email
|
||||
@guest = Guest.find(params[:guest_id])
|
||||
|
||||
mail(
|
||||
to: @guest.wedding.users.pluck(:email),
|
||||
subject: I18n.t(
|
||||
'admin_mailer.attendance_change_email.subject',
|
||||
name: @guest.name,
|
||||
status: I18n.t("active_record.attributes.guest/status.#{@guest.status}")
|
||||
ActsAsTenant.with_tenant(@guest.wedding) do
|
||||
mail(
|
||||
to: recipients,
|
||||
subject: I18n.t(
|
||||
'admin_mailer.attendance_change_email.subject',
|
||||
name: @guest.name,
|
||||
status: I18n.t("active_record.attributes.guest/status.#{@guest.status}")
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def invitations_pdf_email
|
||||
ActsAsTenant.with_tenant(Wedding.find(params[:wedding_id])) do
|
||||
invitations = Invitation.includes(:guests).all
|
||||
|
||||
pdf_html = ActionController::Base.new.render_to_string(
|
||||
template: 'invitations/sheet',
|
||||
layout: 'pdf',
|
||||
locals: { invitations: }
|
||||
)
|
||||
pdf = WickedPdf.new.pdf_from_string(pdf_html)
|
||||
|
||||
attachments["invitations_#{Time.current.strftime('%Y%m%d_%H%M%S')}.pdf"] = pdf
|
||||
|
||||
mail(
|
||||
to: recipients,
|
||||
subject: I18n.t('admin_mailer.invitations_pdf_email.subject')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def recipients
|
||||
ActsAsTenant.current_tenant.users.pluck(:email)
|
||||
end
|
||||
end
|
||||
|
7
app/views/admin_mailer/invitations_pdf_email.html.erb
Normal file
7
app/views/admin_mailer/invitations_pdf_email.html.erb
Normal file
@ -0,0 +1,7 @@
|
||||
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
|
||||
|
||||
<p><%= I18n.t('admin_mailer.greeting') %>,</p>
|
||||
|
||||
<p>
|
||||
<%= I18n.t('admin_mailer.invitations_pdf_email.paragraph_1') %>
|
||||
</p>
|
5
app/views/admin_mailer/invitations_pdf_email.txt.erb
Normal file
5
app/views/admin_mailer/invitations_pdf_email.txt.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
|
||||
|
||||
<%= I18n.t('admin_mailer.greeting') %>,
|
||||
|
||||
<%= I18n.t('admin_mailer.invitations_pdf_email.paragraph_1') %>
|
@ -17,3 +17,6 @@ en:
|
||||
subject: "%{name} has changed their attendance status: %{status}"
|
||||
paragraph_1: "The guest %{name} has changed their attendance for the wedding."
|
||||
notify_on_updates: "You will be notified of any further changes to their attendance status."
|
||||
invitations_pdf_email:
|
||||
subject: "Your wedding invitations are ready"
|
||||
paragraph_1: "Your wedding invitations are ready. Please, find them attached to this email."
|
||||
|
@ -42,7 +42,9 @@ Rails.application.routes.draw do
|
||||
|
||||
resources :tables_arrangements, only: %i[index show create]
|
||||
resources :summary, only: :index
|
||||
resources :invitations, only: %i[show index create update destroy]
|
||||
resources :invitations, only: %i[show index create update destroy] do
|
||||
post :email, on: :collection
|
||||
end
|
||||
|
||||
root to: redirect("/%{slug}")
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user