John Powel
John Powel

Reputation: 1424

How can I use .all for last 2 days in Rails3?

I have a model called submission and currently I am displaying all the records in the database in the index page. In the submissions controller I have :

@submissions = Submission.all

However, now I only want the record for the past two days or the name field equals to some string, I tried this but it still shows all the records for me:

@submissions = Submission.all(:conditions => ["updated_at >= ? OR name = ?", 2.days.ago.to_date, "me"])

where updated_at and name are two fields in the submissions table.

Any idea where is wrong?

EDIT:

In my submission model:

attr_accessible :name, :updated_at

Upvotes: 0

Views: 46

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

In Arel (Rails 3), your conditions should be in a where method, with (optionally) at the end, like so

Submission.where("updated_at >= ? OR name = ?", 2.days.ago.to_date, "me").all

Upvotes: 2

Related Questions