ceth
ceth

Reputation: 45335

Compare updated_at in Rails

time_shift = DateTime.now - 75000
@user.items.where(:updated_at < time_shift) { |item|

I get error

comparison of Symbol with DateTime failed

Why and how to fix it?

In model:

t.datetime "updated_at"

Upvotes: 3

Views: 3455

Answers (2)

Shubham
Shubham

Reputation: 184

John's answer doesn't seems to work with PostgreSQL. If you are using PostgreSQL use:

@user.items.where('"users"."updated_at" < ?', time_shift)

Upvotes: 0

John Beynon
John Beynon

Reputation: 37507

try

@user.items.where("updated_at < ?", time_shift) 

Upvotes: 7

Related Questions