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,
但是,当我尝试发送电子邮件时,邮件,所有变量都返回nil,我假设是因为未明确定义任何内容。即,没有人提交带有电子邮件的表单,单击提交并触发电子邮件,这只是每天发送给所有用户的电子邮件,为简单起见,我们要说其中应包含接收用户的电子邮件地址。
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 %>
在此先感谢您的帮助!
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
,这是实际的电子邮件代码:
and here's the actual e-mail code:
<% @user.account.ideas.each do |idea| %>
<li><%= idea.title %></li>
<% end %>
再次感谢!
推荐答案
在您预定的代码中,您正在通过用户的电子邮件地址传递到邮件发件人 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
.
这篇关于Actionmailer实例变量问题Ruby on Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!