I have a cost attribute for my product model and its type is float and everything works well.
When creating a new product, a user can enter 0 or leave blank for a free product or enter the cost when its a paid product and so far that also works well
Now i am trying to scope free items, but since float is returning NIL for empty fields and i cannot return nil fields.
i tried
scope :free, where("cost IS NULL or cost < ?", 1 )
and it doesn't return fields that are blank (NIL) but fields with 0 only but i want to return both blank (NIL) fields and 0 fields. I know float fields in rails 3 return nil instead of null
Try this:
scope :free, where(:cost => [nil,0] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With