开发者

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,

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 addres开发者_StackOverflows.

     <%= @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). 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜