简体   繁体   中英

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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