Skip to content

Instantly share code, notes, and snippets.

@kplawver
Created December 15, 2009 18:44
Show Gist options
  • Save kplawver/257180 to your computer and use it in GitHub Desktop.
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
# 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