如何在Rails中为多对多自联接创建表单?

时间:2018-02-06 01:37:24

标签: ruby-on-rails ruby

当我点击此表单上的提交时,我得到"依赖必须存在"和"依赖必须存在":

<%= form.label :dependency_ids, "Dependencies" %><br />
<%= form.collection_select :dependency_ids, Article.order(:title),  :id, :title, {}, {multiple: true} %>

<%= form.label :dependent_ids, "Dependencies" %><br />
<%= form.collection_select :dependent_ids, Article.order(:title), :id, :title, {}, {multiple: true} %>

这不是因为我未能在关系控制器中将:dependency_id:dependent_id列入白名单:

def relation_params
  params.require(:relation).permit(:dependency_id, :dependent_id)
end

自动生成的表单&#34;工作&#34;,它实际上保存了关系,但我必须输入数字:

<%= form.label :dependency_id %>
<%= form.number_field :dependency_id, id: :relation_dependency_id %>

<%= form.label :dependent_id %>
<%= form.number_field :dependent_id, id: :relation_dependent_id %>

0 个答案:

没有答案