Rails 3 scope undefined method `includes_values`
My model has this scope
scope :supported, order("name").collect {|m| m.name}.join(", ")
and it throws an error
NoMethodError: undefined method `includes_values' for "blah, blahblah":String
I'm thinking that it's because I'm trying to return a string as an ActiveRecord object, thoughts on how to fix it? Actually I have this code already working in the view but thought it might be better in the model, maybe not?
EDIT Moving it into a non-scope class method works
def supported
order("name").collect {|m| m.name}.join(", ")
end
Here's a related questi开发者_如何转开发on that better clarifies the difference between scope
vs. self
class methods.
what are you trying to do exactly?, if you want to return a string, use class methods. if you want to define a chainable ARel scope, well i'd always recommend to use class methods too, but some prefer the "explicit" way via scope
.
def self.supported
order('name').to_a * ", "
end
精彩评论