Bitwise
Bitwise

Reputation: 8461

Dealing with Time.now in Rails console

I have a Message model and it has a send_at attribute that logs the time it was sent. In the console I'm trying to find the messages that are set for the future. Now I'm putting in the command Message.where(send_at: < Time.now) This is getting an error and I really didn't expect it to work. Does anybody know what the proper command would be for this query.

Upvotes: 1

Views: 1920

Answers (2)

Activerecord:

Message.where("send_at < ?", Time.now)

Mongoid:

Message.where(:send_at.lt => Time.now)

I am writing this off the top of my head but the idea is that.

Upvotes: 2

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

Use the SQL-side query:

Message.where('send_at < NOW()')

Upvotes: 2

Related Questions