title: Delayed Job and ActionMailer not working: "wrong number of arguments (2 for 0..1)"
body: <p>I can't get DJ and ActionMailer to work for me. I always get this error:</p>
  
  <pre><code>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 &lt;top (required)&gt;'
  /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 `&lt;main&gt;'
  </code></pre>
  
  <p>This is my rake task:</p>
  
  <pre><code>namespace :mailer do
      desc "Mail a list of inactive devices"
      task :inactive_devices =&gt; :environment do
          @devices = Device.inactive_devices
          # Send only if we have inactive devices
          SystemMailer.delay.inactive_devices(@devices) unless @devices.empty?
      end
  end
  </code></pre>
  
  <p>My ActionMailer class:</p>
  
  <pre><code>class SystemMailer &lt; ActionMailer::Base
    default from: "Report &lt;system@mymail.com&gt;"
    @@recipients = "Me &lt;censored@mail.com&gt;"
  
    def inactive_devices(devices)
      @devices = devices
      mail(:to =&gt; @@recipients, :subject =&gt; "Inactive Devices")
    end
  end
  </code></pre>
  
  <p>And this is my "inactive_devices" scope on my Device model:</p>
  
  <pre><code>scope :inactive_devices, -&gt; { where("pinged_at &lt; ?", 24.hours.ago).where(:silent =&gt; false) }
  </code></pre>
  
  <p>It works fine without DJ and the delay method.</p>