Actionmailer实例变量问题Ruby on Rails

发布于 2024-11-29 11:28:50 字数 806 浏览 1 评论 0原文

我有一个电子邮件调度程序设置,用于向所有用户发送包含网站更新的每日电子邮件,

但是,当我尝试发送电子邮件时,所有变量都返回为零,我假设是因为没有明确定义任何内容。即没有人用他们的电子邮件提交表单,单击提交并触发电子邮件,这只是发给所有用户的每日电子邮件,为了简单起见,我们会说应该包含接收用户的电子邮件地址。

     <%= @user.email %>

预先感谢您的帮助!

    def newideas_email(user)
    @user = user
    mail(:to => user, :subject => "Here are the latest ideas from your team")
    end

这是调度程序任务:

    scheduler.every("30m") do  
    Account.all.each do |account|
    account.users.each do |user|
    Newideas.newideas_email(user.email).deliver
    end
    end
    end

这是实际的电子邮件代码:

    <% @user.account.ideas.each do |idea| %>  
    <li><%= idea.title %></li> 
    <% end %>

再次感谢!

I have an email scheduler setup to send a daily e-mail with updates about the site to all users,

However, when I try and send the e-mail, all variables come back as nil, i'm assuming because nothing is explicitly defined. i.e. No one is submitting a form with their email, clicking submit and triggering an e-mail, it's just a daily email to all users, that for simplicities sake, we'll say should contain the receiving user's email address.

     <%= @user.email %>

Thanks in advance for the help!

    def newideas_email(user)
    @user = user
    mail(:to => user, :subject => "Here are the latest ideas from your team")
    end

and here's the scheduler task:

    scheduler.every("30m") do  
    Account.all.each do |account|
    account.users.each do |user|
    Newideas.newideas_email(user.email).deliver
    end
    end
    end

and here's the actual e-mail code:

    <% @user.account.ideas.each do |idea| %>  
    <li><%= idea.title %></li> 
    <% end %>

Thanks again!

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

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

发布评论

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

评论(1

温折酒 2024-12-06 11:28:50

在您的预定代码中,您将用户的电子邮件地址传递给邮件程序 Newideas.newideas_email(user.email)。您可能想要做的是传递用户对象本身 Newideas.newideas_email(user),因为您的视图模板期望它是一个 ActiveRecord

In your scheduled code, you're passing through the user's email address to the mailer Newideas.newideas_email(user.email). What you probably meant to do was pass the user object itself Newideas.newideas_email(user), because your view template is expecting it to be an ActiveRecord.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文