开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜