Rails output by date
I am trying to figure out the best way to 开发者_StackOverflow社区display all records by date. I have a date_due column in my database that is a datetime field.
So my output would include every date for which there is an entry, like this:
April 1, 2011
- Buy tickets - Pickup groceriesApril 2, 2011
- Call client
I am trying to use the following method, which is not working: find_all_by_date_due
What's the easiest way to do this in Rails?
Railscasts has a nice cast on group_by :
http://railscasts.com/episodes/29-group-by-month
You could make the dates into an association and assign it an arbitrary ID through rails.
class Entry
belongs_to :date
end
class Date
has_many :entries
end
@entry.date.build(:date => 2011-02-01 20:23:22)
@entry.find_by_date(2)
Date.find(2).date
=> 2011-02-01 20:23:22
精彩评论