1

是否可以在这样的一种形式上具有相同的关联?

<%= 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 %>
4

1 回答 1

0

您可以使用简单的表单嵌套模型支持:

<%= f.simple_fields_for :classifications do |c| %>
  <%= c.input :classification_attribute %>
<% end %>

确保您的父模型允许此关联接受嵌套属性:

accepts_nested_attributes_for :classifications
于 2013-08-23T19:37:23.113 回答