Remove vars_mailer and simplify code

This commit is contained in:
gregoirenovel 2018-05-31 08:56:32 +02:00
parent 2e0abb054c
commit 32a2ab153f

View file

@ -1,6 +1,4 @@
class NotificationMailer < ApplicationMailer class NotificationMailer < ApplicationMailer
default to: Proc.new { @user.email }
def new_answer(dossier) def new_answer(dossier)
subject = "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}" subject = "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}"
@ -35,26 +33,22 @@ class NotificationMailer < ApplicationMailer
private private
def vars_mailer(dossier)
@user = dossier.user
end
def send_mail(dossier, subject) def send_mail(dossier, subject)
vars_mailer(dossier)
@dossier = dossier @dossier = dossier
email = dossier.user.email
mail(subject: subject) mail(subject: subject, to: email)
end end
def send_notification(dossier, mail_template) def send_notification(dossier, mail_template)
vars_mailer(dossier) email = dossier.user.email
subject = mail_template.subject_for_dossier(dossier) subject = mail_template.subject_for_dossier(dossier)
body = mail_template.body_for_dossier(dossier) body = mail_template.body_for_dossier(dossier)
create_commentaire_for_notification(dossier, subject, body) create_commentaire_for_notification(dossier, subject, body)
mail(subject: subject) { |format| format.html { body } } mail(subject: subject, to: email) { |format| format.html { body } }
end end
def create_commentaire_for_notification(dossier, subject, body) def create_commentaire_for_notification(dossier, subject, body)