Ruby on Rails: Find records based on a method in the model?
- by sjsc
I'm looking to use named_scope to find records based on a method in the model. Right now I have in my Order.rb model:
def self.paid
collect { |order| order if order.paid? }
end
# the method
def paid
order.payments.total >= order.total_price
end
That works, but I can't chain it if I have a shipped named_scope:
named_scope :shipped, :conditions => "shipped is true"
And I wanted to do:
Order.paid.shipped
which doesn't work. Any ideas?