当我点击此表单上的提交时,我得到"依赖必须存在"和"依赖必须存在":
<%= 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 %>