Testing for nil numeric value in find

In the agile/rails tutorial book the following construct is added
to products.rb.

def self.salable_items
find( :all,
:conditions => “date_available <= now()”,
:order => “date_available desc”)
end

Now, I wish to extend :conditions => to exclude products that have
a nil value for the price. I have tried different syntax using
“price.nil?”, “not”, and “!”, but have not hit upon the right
combination. Can someone show me the way?

Regards,
Jim


*** e-mail is not a secure channel ***
mailto:byrnejb.@harte-lyne.ca
James B. Byrne Harte & Lyne Limited
vox: +1 905 561 1241 9 Brockley Drive
fax: +1 905 561 0757 Hamilton, Ontario
= hal Canada L8E 3C3

Hi,
I haven’t tested this, but I think it should work.

def self.salable_items
find( :all,
:conditions => [“(date_available <= ?) AND (price <>
|NULL|)”,Time.now()],
:order => “date_available desc”)
end

Eric

James B. Byrne wrote:

Now, I wish to extend :conditions => to exclude products that have
James B. Byrne Harte & Lyne Limited
vox: +1 905 561 1241 9 Brockley Drive
fax: +1 905 561 0757 Hamilton, Ontario
= hal Canada L8E 3C3


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Eric G.
http://www.ericgoodwin.com

Disregard the pipes in the statement, I think my editor added them in by
accident.

Eric G. wrote:

Eric

      :order        =>  "date_available desc")

http://lists.rubyonrails.org/mailman/listinfo/rails


Eric G.
http://www.ericgoodwin.com

def self.salable_items
find( :all,
:conditions => “date_available <= now() && price > 0”,
:order => “date_available desc”)
end

Since price is defined as not null and a decimal, its default value will
be
0.00 (I think). Adding an SQL check for price > 0 will give what you
want.

Bob S.
http://www.railtie.net/