I’m rails a newbie:
I have a form setup where users selects datetime, the datetime serves
the purpose of allowing the user to specify when the entry expires. In
efforts to filter entrys that have an earlier datetime than now I am
using the following:
def self.find_active
find(:all, :conditions => [‘expiration > ?’, DateTime.now])
It does not filter out the expiration inputs that are further in advance
than DateTime.now
Any help would be greatly appreciated
On Oct 1, 6:27 am, Greg K. [email protected] wrote:
I’m rails a newbie:
I have a form setup where users selects datetime, the datetime serves
the purpose of allowing the user to specify when the entry expires. In
efforts to filter entrys that have an earlier datetime than now I am
using the following:
def self.find_active
find(:all, :conditions => [‘expiration > ?’, DateTime.now])
You’ve got your condition back to front - that returns entries whose
expiry is after now
Fred
Frederick C. wrote:
On Oct 1, 6:27�am, Greg K. [email protected] wrote:
I’m rails a newbie:
I have a form setup where users selects datetime, the datetime serves
the purpose of allowing the user to specify when the entry expires. �In
efforts to filter entrys that have an earlier datetime than now I am
using the following:
def self.find_active
� � find(:all, :conditions => [‘expiration > ?’, DateTime.now])
You’ve got your condition back to front - that returns entries whose
expiry is after now
I don’t think he’s got it backwards – he’s looking for entries that
haven’t yet expired.
Fred
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Rails Newb wrote:
def self.find_active
find(:all, :conditions => [‘expiration > ?’, DateTime.now])
On a side note: Wouldn’t this be a good candidate for a named_scope
rather than a class method?
named_scope :active, lamda { :conditions => [ ‘expiration > ?’,
DateTime.now ] }
or
named_scope :active, lamda { :conditions => [ ‘expiration <= ?’,
DateTime.now ] }
or whatever conditions you determine are the right ones for your case.
P.S. This would be more conventional to the Rails framework:
named_scope :active, lamda { :conditions => [ ‘expires_at > ?’,
DateTime.now ] }
where expires_at is a datetime column in the database.
2009/10/1 Greg K. [email protected]:
I’m rails a newbie:
I have a form setup where users selects datetime, the datetime serves
the purpose of allowing the user to specify when the entry expires. Â In
efforts to filter entrys that have an earlier datetime than now I am
It is not completely clear from the above whether you are trying to
select records with an expiry date greater than now or earlier than
now.
using the following:
def self.find_active
  find(:all, :conditions => [‘expiration > ?’, DateTime.now])
It does not filter out the expiration inputs that are further in advance
than DateTime.now
What type of column (in the database) is expiration?
Colin