Created
July 18, 2012 00:33
-
-
Save johnkoht/3133193 to your computer and use it in GitHub Desktop.
Rails Apps Common Scopes
This file contains hidden or 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
module CommonScopes | |
def self.included(base) | |
base.class_eval { | |
# Filtering by the state of the record | |
scope :active, where(:parent_id => nil, :deleted_at => nil) #.order('sort_order asc') | |
scope :published, where('published_at IS NOT NULL', :deleted_at => nil) | |
scope :unpublished, where(:published_at => nil, :deleted_at => nil) | |
scope :deleted, where('deleted_at IS NOT NULL') | |
scope :not_deleted, where(:deleted_at => nil) | |
# Sorting | |
scope :by_date, order("published_at asc") | |
scope :sorted, order("sort_order asc") | |
scope :created_date, order("created_at asc") | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment