我有这样的代码:
user.posts.size #=> 5 already saved
user.posts.new(title:"foo")
user.posts.new(title:"bar")
user.posts.sort_by! { |e| e.title } #=> sort correclty
user.posts #=> sorted but with the saved on the top, the new one at the bottom
我使用排序,field_for
但显然它仍然未排序。
使用:Rails 3.2.11 和 Mongoid 3.0.23