title: Using ActiveRecord find_in_batches method for deleting large data
body: <p>Okay, so I know that when dealing with very large data, we can use <code>find_in_batches</code> which, as I understand it, does the work of <code>Model.all.each</code> in a really fast way which is much more efficient</p>
  
  <p>Now, I have a really large data I'm trying to delete, and I'm thinking of using this same <code>find_in_batches</code> to delete them in batches.</p>
  
  <p>below is what I have (from within the rake task <code>database.rake</code>):</p>
  
  <pre><code>old_messages = TextMessage.where("created_at &lt; ?", number.days.ago )
  
  old_messages.find_in_batches do |batch|
    batch.delete_all
  end
  </code></pre>
  
  <p>When I run this however, I get the following error:</p>
  
  <pre><code>ArgumentError: wrong number of arguments (0 for 1..3)
  /Users/Sunday/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.5/lib/httparty.rb:66:in `logger'
  /Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/delegation.rb:94:in `public_send'
  /Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/delegation.rb:94:in `block in method_missing'
  /Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation.rb:302:in `scoping'
  /Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/delegation.rb:94:in `method_missing'
  /Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/batches.rb:112:in `find_in_batches'
  /Users/Sunday/workspace/resilience/lib/tasks/database.rake:18:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>where <code>database.rake</code> on line 18 is: <code>old_messages.find_in_batches do |batch|</code>.</p>
  
  <p>So, is it possible to use <code>find_in_batches</code> for deleting like I'm trying to do? and what am I doing wrong, if the answer to that is yes. Thanks for all response. </p>