Ruby on rails 在Rails中记录传出的电子邮件
我有两种型号,用户和电子邮件 我在用户创建后有一个after_create回调,它向用户的电子邮件地址发送确认电子邮件 user.rbRuby on rails 在Rails中记录传出的电子邮件,ruby-on-rails,Ruby On Rails,我有两种型号,用户和电子邮件 我在用户创建后有一个after_create回调,它向用户的电子邮件地址发送确认电子邮件 user.rb after_create :create_confirmation_email private def creation_confirmation_email UserMailer.account_create_confirmation(self).deliver end def account_create_confirmat
after_create :create_confirmation_email
private
def creation_confirmation_email
UserMailer.account_create_confirmation(self).deliver
end
def account_create_confirmation(user)
I18n.locale = 'pt'
@user = user
mail(from: 'no-reply@miigo.com.br', to: @user.email, subject: 'Bem-vindo ao Miigo') do |format|
format.text
format.html
end
end
上面的创建确认电子邮件连接到mailer/user\u mailer.rb中的方法
after_create :create_confirmation_email
private
def creation_confirmation_email
UserMailer.account_create_confirmation(self).deliver
end
def account_create_confirmation(user)
I18n.locale = 'pt'
@user = user
mail(from: 'no-reply@miigo.com.br', to: @user.email, subject: 'Bem-vindo ao Miigo') do |format|
format.text
format.html
end
end
user\u mailer.rb
after_create :create_confirmation_email
private
def creation_confirmation_email
UserMailer.account_create_confirmation(self).deliver
end
def account_create_confirmation(user)
I18n.locale = 'pt'
@user = user
mail(from: 'no-reply@miigo.com.br', to: @user.email, subject: 'Bem-vindo ao Miigo') do |format|
format.text
format.html
end
end
我的电子邮件模型具有以下属性:
reply_to: string
first_name: string
last_name :string
subject: string
现在我想要的是一个动作,在每次发送后记录确认电子邮件信息
你能建议一个解决方法或回拨吗
您可以在
ActionMailer
类中编写回调函数,所有这些都会得到赞赏
如果您使用的是Rails 3,IIRC可以通过包含AbstractController::Callbacks
向ActionMailer
类添加回调功能
比如:
class MyMailer < ActionMailer::Base
include AbstractController::Callbacks
after_filter :audit_email
def account_create_confirmation(user)
@subject = 'Bem-vindo ao Miigo'
# ...
end
def audit_email
EmailAudit.create(subject: @subject, ...)
end
end
classmymailer
谢谢。顺便问一下,我怎样才能知道电子邮件的主题呢?抱歉,这是我第一次这么广泛地使用action mailer。