开发者

Rails 3 scope undefined method `includes_values`

开发者 https://www.devze.com 2023-04-09 09:53 出处:网络
My model has this scope scope :supported, order(\"name\").collect {|m| m.name}.join(\", \") and it throws an error

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

精彩评论

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

关注公众号