fl0*_*00r 5 ruby ruby-on-rails mongodb mongoid
如何将默认顺序设置为嵌入对象,例如:
class Post
embeds_many :comments, :order => "author"
accepts_nested_attributes_for
end
Run Code Online (Sandbox Code Playgroud)
现在我直接通过订单来处理它:
f.fields_for :comments, @post.comments.asc(:author) do |comment|
...
end
Run Code Online (Sandbox Code Playgroud)
在mongoid 3.1.2中,您可以执行以下操作:
embeds_many :favorites, order: :title.desc
Run Code Online (Sandbox Code Playgroud)
它也适用 :title.asc