我正在尝试使用 heroku 的调度程序和 rake 任务向自己发送每日报告。
在 scheduler.rake 我有
task :send_report => :environment do
user_count = User.count
share_count = Share.count
ReportMailer.send(user_count, share_count).deliver
end
我的 ReportMailer 看起来像这样
class ReportMailer < ActionMailer::Base
def send(user_count, share_count)
@user_count = user_count
@share_count = share_count
mail(from: "email@example.com", to: "email@spam.com", subject: "Report")
end
end
我有视图 send.html.erb
<p>Report</p>
<p>Users: <%= @user_count %></p>
<p>Shares: <%= @share_count %></p>
运行时出现错误heroku run rake send_report
Sending report...
(1.6ms) SELECT COUNT(*) FROM "users"
(1.3ms) SELECT COUNT(*) FROM "shares"
rake aborted!
2 is not a symbol
/app/lib/tasks/scheduler.rake:5:in `block in <top (required)>'
Tasks: TOP => send_report
User.count = 2 所以我假设我必须以不同的方式传递“计数”?