我无法让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
这是我的设备型号上的“inactive_devices”范围:
scope :inactive_devices, -> { where("pinged_at < ?", 24.hours.ago).where(:silent => false) }
没有DJ和延迟方法,它可以正常工作。
答案 0 :(得分:3)
您需要在.all
条款的末尾添加where
才能使用delayed_job
。
all
应该返回一个数组,而where
返回一个ActiveRecord关系(如果我理解正确的话)。