Update: As of Rails 4.1.4 this is possible. See this answer for more. Example:
User.find_each(:batch_size => 1000).with_index do |user, index| user.call_method(index) end
As you can see from the method definition, this is not possible.
def find_each(options = {}) find_in_batches(options) do |records| records.each { |record| yield record } end end
In order to accomplish what you want to do, you need to either create your own modified version of the method
class User def find_each(options = {}) find_in_batches(options) do |records| records.each_with_index { |record| yield record, index } end end end User.find_each(:batch_size => 10000) do |user, index| ------ end
or use an instance variable.
index = 0 User.find_each(:batch_size => 10000) do |user| # ... index += 1 end
There is no other default solution as shown by the method implementation.