Skip to content

Instantly share code, notes, and snippets.

module ActiveRecord
module Batches # :nodoc:
def self.included(base)
base.extend(ClassMethods)
end
# When processing large numbers of records, it's often a good idea to do
# so in batches to prevent memory ballooning.
module ClassMethods
# Yields each record that was found by the find +options+. The find is
@rumblex
rumblex / gist:177795
Created August 30, 2009 00:36
Rails Rumble Alumni
Rails Rumble 'Alumni'
2007:
* http://tastyplanner.com
* ???
2008:
* http://prioritizd.com
# 2.3
named_scope :last_active_since, lambda { |la| la = 10.minutes.ago if la.nil?; {:conditions => ['last_active_at >= ?', la]}}
# 3 scopes
named_scope :last_active_since, lambda { |la| la = 10.minutes.ago if la.nil?; where('last_active_at >= ?', la) }
# 3 method