mercredi 5 août 2015

rake aborted! ArgumentError: wrong number of arguments (2 for 0..1)

My rails task looks like this:

  desc 'Delete records older than 7 days'
  task :delete_old_records => :environment do
  Post.delete_all('created_at < ?', 7.days.ago)
  end

I tried to execute the task using:

 rake delete_old_records --trace

and it results to this error:

** Invoke delete_old_records (first_time)                                                                                                                                                                                                                             
** Invoke environment (first_time)                                                                                                                                                                                                                                    
** Execute environment                                                                                                                                                                                                                                                
** Execute delete_old_records                                                                                                                                                                                                                                         
rake aborted!                                                                                                                                                                                                                                                         
ArgumentError: wrong number of arguments (2 for 0..1)                                                                                                                                                                                                                 
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:453:in `delete_all'                                                                                                                                       
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/querying.rb:8:in `delete_all'                                                                                                                                         
/home/codio/workspace/lib/tasks/delete_old_records.rake:3:in `block in <top (required)>'                                                                                                                                                                              
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'                                                                                                                                                                 
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'                                                                                                                                                     
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'                                                                                                                                                                 
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'                                                                                                                                                              
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'                                                                                                                                      
/home/codio/.rbenv/versions/2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'                                                                                                                                                                                  
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'                                                                                                                                               
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'                                                                                                                                                               
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'                                                                                                                                                   
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'                                                                                                                                 
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'                                                                                                                                                          
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'                                                                                                                                            
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'                                                                                                                                              
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'                                                                                                                                                     
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'                                                                                                                                                   
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'                                                                                                                                   
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'                                                                                                                                                            
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'                                                                                                                                                              
/home/codio/.rbenv/versions/2.1.5/bin/rake:23:in `load'                                                                                                                                                                                                               
/home/codio/.rbenv/versions/2.1.5/bin/rake:23:in `<main>'    

Does anyone know what I could be doing wrong here? My model looks like:

class Post < ActiveRecord::Base
end

Aucun commentaire:

Enregistrer un commentaire