Rails 3 fields_for - sort order gets lost

社会主义新天地 提交于 2019-12-03 02:07:21

According to the Rails Documentation for fields_for, you can also specify the record object after the record name.

So something like this should work...

<%= f.fields_for :profile_items, @profile_items do |f2| %>
  <%= render 'profile_item_fields', :f => f2 %>
<% end %>

This can be accomplished with a default_scope on the nested model:

class YourModel < ActiveRecord::Base
  belongs_to :other_model
  default_scope { order(:name) }
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!