DJ と ActionMailer が動作しません。私はいつもこのエラーを受け取ります:
rake aborted!
wrong number of arguments (2 for 0..1)
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/arel-3.0.2/lib/arel/expressions.rb:3:in `count'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:81:in `payload_object='
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `each'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/base.rb:498:in `initialize'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:29:in `new'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:29:in `enqueue'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/message_sending.rb:13:in `method_missing'
/Users/drale2k/Dropbox/htdocs/work/etaxi/code/etaxi/lib/tasks/mailers.rake:6:in `block (2 levels) in <top (required)>'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'
これは私のレーキタスクです:
namespace :mailer do
desc "Mail a list of inactive devices"
task :inactive_devices => :environment do
@devices = Device.inactive_devices
# Send only if we have inactive devices
SystemMailer.delay.inactive_devices(@devices) unless @devices.empty?
end
end
私の ActionMailer クラス:
class SystemMailer < ActionMailer::Base
default from: "Report <system@mymail.com>"
@@recipients = "Me <censored@mail.com>"
def inactive_devices(devices)
@devices = devices
mail(:to => @@recipients, :subject => "Inactive Devices")
end
end
そして、これは私の Device モデルの "inactive_devices" スコープです:
scope :inactive_devices, -> { where("pinged_at < ?", 24.hours.ago).where(:silent => false) }
DJ と遅延メソッドなしで正常に動作します。