Reputation: 6056
I have the following code:
@gameRequests = GameRequest.find(:first, :conditions => ["created_on >= ?", created_on])
I'd like to find the oldest record within the last 5 minutes. How can I subtract the 5 minutes from created_on to do this? I cant seem to find any examples.
Thanks
Upvotes: 0
Views: 2732
Reputation: 153
Try this:
@gameRequests = GameRequest.find(:first, :conditions => ["created_at >= ?", Time.now - 5.minutes], :order => "created_at ASC")
Upvotes: 1
Reputation: 8202
The code you want is:
@gameRequest = GameRequest.first(:conditions => ["created_on >= ?", DateTime.now - 5.minutes])
BTW, are you sure the field is named created_on and not created_at? Also, .first gets only the first record, not all of them. For that, you need .all
Upvotes: 1
Reputation: 83680
gameRequests = GameRequest.find(:first, :conditions => ["created_on >= ?", created_on - 5.minute])
Upvotes: 1