开发者

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 groceries

April 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜