以下代码正在编辑,它会根据订单显示详细信息。但是当我尝试添加新细节,提交它并进行验证时,我看不到新添加的细节。所以试图删除顺序,它显示所有细节。
代码:
<%= simple_form_for @master_template, :html=> { class: "form-horizontal style-form" } do |f| %>
<%= f.simple_fields_for :master_template_details, f.object.master_template_details.order("name DESC"), :wrapper => false do |p| %>
<%= render 'master_template_detail_fields', {f: p} %>
<% end %>
<% end %>
我也试过这个:
#model
scope :ordered, -> { order("name DESC") }
belongs_to :master_template
#view
<%= simple_form_for @master_template, :html=> { class: "form-horizontal style-form" } do |f| %>
<%= f.simple_fields_for :master_template_details, f.object.master_template_details.ordered, :wrapper => false do |p| %>
<%= render 'master_template_detail_fields', {f: p} %>
<% end %>
<% end %>
但仍然无效