如何使用Heroku的调度程序发送每日报告

时间:2013-10-11 07:04:13

标签: ruby-on-rails ruby heroku actionmailer scheduler

我尝试使用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所以我假设我必须通过&#39;计数&#39;以不同的方式?

1 个答案:

答案 0 :(得分:1)

sendObject的方法defined。重命名邮件操作。