Created
December 15, 2009 18:44
-
-
Save kplawver/257180 to your computer and use it in GitHub Desktop.
Add this to your ActiveRecord models for an easy "find me everything that happened on this day" named scope
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 to your ActiveRecord models for an easy "find me everything that happened on this day" named scope: | |
named_scope :by_date, lambda {|date| | |
if date.is_a?(String) | |
date = Time.parse(date) | |
end | |
date_start = date.midnight | |
date_end = date_start.advance(:hours => 24) | |
{ | |
:conditions => ["created_at between ? and ?",date_start,date_end] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment