-
Notifications
You must be signed in to change notification settings - Fork 1
sander6/timed_scopes
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
=== Timed Scopes Times Scopes is a simple plugin to add some named scopes to your model based on their time columns. = Usage class Post < ActiveRecord::Base has_timed_scopes end = What It Does Calling has_timed_scopes will reflect on the model's columns and add three scopes for each column ending in "_at" or "_on". For example, a model with a published_at column gets "published_after", "published_before", and "published_between". Post.published_after(1.month.ago) # => :conditions => ['posts.published_at > ?', 1.month.ago] Post.published_before(1.year.ago) # => :conditions => ['posts.published_at < ?', 1.year.ago] Post.published_between(2.months.ago, 1.month.ago) # => :conditions => ['posts.published_at > ? AND posts.published_at < ?', 2.months.ago, 1.month.ago] By default, each timed scope will order the results on that column descending. You can ascend by passing "ASC" as an additional argument. Post.published_before(1.year.ago, "ASC") Or you can return the results unordered by passing false as an additional argument. Post.published_before(1.year.ago, false)
About
Simple Rails plugin for named_scopes based on time columns
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published