是否可以在一个表单上拥有相同的关联,例如?
<%= f.association :classifications, label: "Recipient", collection: @classifications, input_html: {class: "parent_recipients"}, as: :collection_select %>
<%= f.association :classifications, label: "Sub-recipient", collection: @sub_classifications, input_html: {class: "sub_recipients"}, as: :collection_select %>
这样用户可以从这两个选择框中进行选择并将两个条目保存到数据库中吗?
编辑:
<%= f.simple_fields_for :classifications do |c| %>
<%= f.input :classification_ids, label: "Recipient", collection: @cat, as: :collection_select %>
<%= f.input :classification_ids, label: "Sub-recipient", collection: @sub, as: :collection_select %>
<% end %>
答案 0 :(得分:0)
您可以使用简单表单嵌套模型支持:
<%= f.simple_fields_for :classifications do |c| %>
<%= c.input :classification_attribute %>
<% end %>
确保您的父模型允许为此关联接受嵌套属性:
accepts_nested_attributes_for :classifications