如何使用 Devise 和 Rails 3 从邮件程序访问 @user 或 user?

发布于 2024-10-21 02:20:43 字数 541 浏览 4 评论 0原文

class JobMailer < ActionMailer::Base

default :from => "[email protected]"

def new_job_email_for_client
#
#
@url = "http://simplesite.com/users/login"
mail(:to => @???,
      :subject => "You have created a new case on simplesite.")
end

end

我希望每个用户每次创建“工作”时都会收到一封电子邮件。在应用程序的其他部分,我可以访问 @user 和 user.email 等,但在邮件程序中我收到“未定义的错误”。

我如何访问邮件程序中当前用户的电子邮件地址(考虑到 Devise 控制着用户)?

class JobMailer < ActionMailer::Base

default :from => "[email protected]"

def new_job_email_for_client
#
#
@url = "http://simplesite.com/users/login"
mail(:to => @???,
      :subject => "You have created a new case on simplesite.")
end

end

I would like each user to receive an email each and every time he/she creates a "job." In other parts of the application, I can access @user and user.email and such, but in the mailer I'm getting "undefined errors."

How can I access the current users email address in the mailer (taking into consideration that Devise is in control of Users)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混浊又暗下来 2024-10-28 02:20:43

我不确定这是否是一个很好的方法,但这就是我让它工作的方法:

def new_job_email_for_client(user_email)
@url = "http://simplesite.com/users/login"
mail(:to => user_email,
      :subject => "You have created a new case.")
end

I'm not sure if this is a great way of doing it, but this is how I got it working:

def new_job_email_for_client(user_email)
@url = "http://simplesite.com/users/login"
mail(:to => user_email,
      :subject => "You have created a new case.")
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文