我的应用程序正常工作,因为我的 4条记录在我的表单中已经包含相同的字段(:name
,:family_with
),用户需要填写{{1} }。
(PS:我使用的是嵌套表格和cocoon gem)。
这是我的表格:
:name
我在寻找的是,每次填充= f.simple_fields_for :families do |family|
= f.text_field :name
= f.collection_select :family_with, Family.where(family_id: @family), :id, :name, {include_blank: "Choose a name"}
时如何更新collection_select :family_with
,以便我的f.text_field :name
可以填充名称&# 39;已插入每个collection_select :family_with
。
我已经读过,我可以使用ajax或jQuery来完成它,但我会很感激任何代码解决方案。
答案 0 :(得分:0)
= f.collection_select :family_with, Family.all.where(family_id: @family), :id, :name, {include_blank: "Choose a name"},selected: f.object.family_with
答案 1 :(得分:0)
Not sure what you consider a "code solution" but if you mean through ruby/rails then you have to at least submit the form to get any updates in the collection_select
When I had to do something with dependent/dynamic select menus this page was very useful for me (involves jQuery): http://blog.kate-travers.com/dynamic-duos-dependent-select-with-jquery-and-rails/