demarches-normaliennes/app/controllers/new_administrateur/mail_templates_controller.rb
Pierre de La Morinerie 858b093314 mailers: use the standard view mechanism to render notifications
Instead of rendering a view as a template, consider the view as a normal
view.
2019-07-23 14:53:50 +02:00

36 lines
1,016 B
Ruby

module NewAdministrateur
class MailTemplatesController < AdministrateurController
include ActionView::Helpers::SanitizeHelper
def preview
@procedure = procedure
@logo_url = procedure.logo.url
@service = procedure.service
mail_template = find_mail_template_by_slug(params[:id])
@rendered_template = sanitize(mail_template.body)
render(template: 'notification_mailer/send_notification', layout: 'mailers/notifications_layout')
end
private
def procedure
@procedure = current_administrateur.procedures.find(params[:procedure_id])
end
def mail_templates
[
@procedure.initiated_mail_template,
@procedure.received_mail_template,
@procedure.closed_mail_template,
@procedure.refused_mail_template,
@procedure.without_continuation_mail_template
]
end
def find_mail_template_by_slug(slug)
mail_templates.find { |template| template.class.const_get(:SLUG) == slug }
end
end
end