Ruby on Rails: Find records based on a method in the model?

Posted by sjsc on Stack Overflow See other posts from Stack Overflow or by sjsc
Published on 2010-03-30T01:51:37Z Indexed on 2010/03/30 1:53 UTC
Read the original article Hit count: 346

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails