Last active
February 23, 2017 15:56
-
-
Save neomindryan/d38d3f97dca7378feca46c2bb0b0e0c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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