我已经有了一个可行的解决方案,但我真的想知道为什么这不起作用:
ratings = Model.select(:rating).uniq
ratings.each { |r| puts r.rating }
Run Code Online (Sandbox Code Playgroud)
它选择但不打印唯一值,它会打印所有值,包括重复值.它在文档中:http://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields
我正在使用RubyMine,rails 3.2.12我在IDE中得到了不推荐使用的警告.任何想法如何解决这个已弃用的警告?
find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2.
Run Code Online (Sandbox Code Playgroud)