Skip to content

Instantly share code, notes, and snippets.

@abriening
Created September 27, 2012 19:29
Show Gist options
  • Save abriening/3795954 to your computer and use it in GitHub Desktop.
Save abriening/3795954 to your computer and use it in GitHub Desktop.
ActiveRecord::Base.class_eval do
# Setup some useful generic scopes
named_scope :ordered, proc{ { :order => primary_key } }
named_scope :where, proc{|*conditions| { :conditions => conditions.size == 1 ? conditions.first : conditions } }
named_scope :joins, proc{|joins| { :joins => Array(joins).join(' ') } }
named_scope :limit, proc{|count| { :limit => count } }
named_scope :offset, proc{|offset| { :offset => offset } }
named_scope :order, proc{|order| { :order => order.to_s } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment