Skip to content

Instantly share code, notes, and snippets.

@johnkoht
Created July 18, 2012 00:33
Show Gist options
  • Save johnkoht/3133193 to your computer and use it in GitHub Desktop.
Save johnkoht/3133193 to your computer and use it in GitHub Desktop.
Rails Apps Common Scopes
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