Actionmailer instance variable problem Ruby on Rails

只谈情不闲聊 提交于 2019-12-11 09:23:52

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/7054521/actionmailer-instance-variable-problem-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!