简体   繁体   English

Actionmailer 实例变量问题 Ruby on Rails

[英]Actionmailer instance variable problem Ruby on Rails

I have an email scheduler setup to send a daily e-mail with updates about the site to all users,我有一个 email 调度程序设置,用于向所有用户发送每日电子邮件,其中包含有关该站点的更新,

However, when I try and send the e-mail, all variables come back as nil, i'm assuming because nothing is explicitly defined.但是,当我尝试发送电子邮件时,所有变量都返回为零,我假设是因为没有明确定义。 ie 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.即没有人用他们的 email 提交表单,单击提交并触发电子邮件,这只是对所有用户的每日 email,为简单起见,我们会说应该包含接收用户的 email 地址。

     <%= @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!再次感谢!

In your scheduled code, you're passing through the user's email address to the mailer Newideas.newideas_email(user.email) .在您计划的代码中,您将用户的 email 地址传递给邮件程序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 .您可能打算做的是传递用户 object 本身Newideas.newideas_email(user) ,因为您的视图模板期望它是ActiveRecord

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM