gpt4 book ai didi

ruby-on-rails - 在 devise_invitable 中覆盖邮件程序?

转载 作者:行者123 更新时间:2023-12-04 17:04:25 29 4
gpt4 key购买 nike

我希望我的应用程序的邀请来自邀请者而不是系统电子邮件地址。如何从 devise.rb 覆盖 config.mailer_sender?

我在我的邮件中有这个并且已经确认它被调用了,但是它没有覆盖 :from .注意:这是一个私有(private)方法,我尝试了它作为一个公共(public)方法没有效果。

private

def headers_for(action)
if action == :invitation_instructions
headers = {
:subject => "#{resource.invited_by.full_name} has invited you to join iTourSmart",
:from => resource.invited_by.email,
:to => resource.email,
:template_path => template_paths
}
else
headers = {
:from => mailer_sender(devise_mapping),
:to => resource.email,
:template_path => template_paths
}
end

if resource.respond_to?(:headers_for)
headers.merge!(resource.headers_for(action))
end

unless headers.key?(:reply_to)
headers[:reply_to] = headers[:from]
end

headers
end

最佳答案

没有任何 hacks/monkey 补丁的更好的解决方案是:
例如,在您的模型中:

def invite_and_notificate_member user_email
member = User.invite!({ email: user_email }, self.account_user) do |u|
u.skip_invitation = true
end
notificate_by_invitation!(member)
end

def notificate_by_invitation! member
UserMailer.invited_user_instructions(member, self.account_user, self.name).deliver
end

在邮件中:
  def invited_user_instructions(user, current_user, sa)
@user = user
@current_user = current_user
@sa = sa
mail(to: user.email, subject: "#{current_user.name} (#{current_user.email}) has invited you to the #{sa} account ")
end

因此,您可以将任何主题/数据放在邮件正文中。

祝你好运!

关于ruby-on-rails - 在 devise_invitable 中覆盖邮件程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6412761/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com