views:

97

answers:

2

Hi, I'd like to get the objects that are updated in the last 10 seconds from the ActiveRecord's find.

I tried doing this

@chats = Chat.find(:all, :conditions => ["updated_at > ?", 10.seconds.ago] )

as well as

@chats = Chat.find(:all, :conditions => ["updated_at > ?", Time.now-10.seconds] )

and even

@chats = Chat.find(:all, :conditions => {:updated_at => 10.seconds.ago..0.seconds.ago}]

But I still can't get it to work :(

EDIT: I am updating the column from another application to keep it alive and I'm looking at all the rows I kept alive in the last 10 seconds, to dispose the dead chats.

+2  A: 

Are you sure that you are querying on the right column? I am thinking that you might need to look at the created_at timestamp instead. I don't know your application, but I am surprised you are updating existing chats, instead of just inserting new ones.

So... if my assumption is correct, this might be what you are looking for:

@chats = Chat.find(:all, :conditions => ["created_at > ?", 10.seconds.ago] )

If not... please provide a little more info. The query should work as you have it, and I am guessing the updated_at may not be getting updated.

Scott Miller
Hi. Thanks for replying. I updated the post. Basically, I need to display only alive columns and I am modifying a column to keep alive.
mannicken
I check the date/time manually in SQL and it looks correct.
mannicken
Have you confirmed that the date is being updated in your Rails app, and that the date is in the correct format for your database?
Scott Miller
A: 

The problem was in UTC-default of Rails. I changed it to config.time_zone = 'Pacific Time (US & Canada)' and now it works alright :)

mannicken
Ahhhhh, yes. I guess that would do it, if your systems were not using the same time zone.
Scott Miller