I'm trying (and failing) to construct a find all statement with conditions in rails for what I need. I need to find a开发者_如何转开发ll the values where where the 'in' value in a table is greater than 0 (or just not zero would be fine) but I am having trouble with this, here's what I need:
@sales = Transaction.find(:all, :conditions => {:in => 'greater than 0'} )
Is there a simple way to do this?
Thanks,
Tom
You can use Arel to do this without having to reach into SQL:
@sales = Transaction.where(Transaction.arel_table[:in].gt(0)).all
Try this
@sales = Transaction.find(:all, :conditions => ['in > ?', 0] )
OR use conditions like
:conditions => 'in > 0'
精彩评论