Actionmailer实例变量问题Ruby on Rails
我有一个电子邮件调度程序设置,用于向所有用户发送包含网站更新的每日电子邮件,
但是,当我尝试发送电子邮件时,所有变量都返回为零,我假设是因为没有明确定义任何内容。即没有人用他们的电子邮件提交表单,单击提交并触发电子邮件,这只是发给所有用户的每日电子邮件,为了简单起见,我们会说应该包含接收用户的电子邮件地址。
<%= @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
这是实际的电子邮件代码:
<% @user.account.ideas.each do |idea| %>
<li><%= idea.title %></li>
<% end %>
再次感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的预定代码中,您将用户的电子邮件地址传递给邮件程序
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 itselfNewideas.newideas_email(user)
, because your view template is expecting it to be anActiveRecord
.