Skip to content

Instantly share code, notes, and snippets.

@neomindryan
Last active February 23, 2017 15:56
Show Gist options
  • Save neomindryan/d38d3f97dca7378feca46c2bb0b0e0c7 to your computer and use it in GitHub Desktop.
Save neomindryan/d38d3f97dca7378feca46c2bb0b0e0c7 to your computer and use it in GitHub Desktop.
# Add this file to config/initializers in a Rails 2 app
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