Scott
Scott

Reputation: 977

Rails output by date

I am trying to figure out the best way to 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?

Upvotes: 0

Views: 111

Answers (2)

Kyle Macey
Kyle Macey

Reputation: 8154

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

Upvotes: 0

Spyros
Spyros

Reputation: 48626

Railscasts has a nice cast on group_by :

http://railscasts.com/episodes/29-group-by-month

Upvotes: 3

Related Questions