Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails中的双嵌套表单-HTML字段为空_Ruby On Rails - Fatal编程技术网

Ruby on rails Rails中的双嵌套表单-HTML字段为空

Ruby on rails Rails中的双嵌套表单-HTML字段为空,ruby-on-rails,Ruby On Rails,在我的Rails 4应用程序中,我有三种型号: 挑战的有序列表(存储在ListJoin表中的位置): 我尝试制作一个表格,在其中我可以同时编辑列表中的挑战及其位置: = form_for @challenge_list do |f| -# ...fields for list... = f.fields_for :list_joins do |links_form| .field = links_form.number_field :position =

在我的Rails 4应用程序中,我有三种型号:

挑战的有序列表(存储在
ListJoin
表中的位置):

我尝试制作一个表格,在其中我可以同时编辑列表中的挑战及其位置:

= form_for @challenge_list do |f|
  -# ...fields for list...
  = f.fields_for :list_joins do |links_form|
     .field
       = links_form.number_field :position
     = links_form.fields_for :challenges do |challenge_form|
       .field
         -# The following fields will be empty
         = challenge_form.text_field :description
         = challenge_form.text_field :id -# Added to test I didn't make a typo on 'description'
当我测试表单时,它呈现OK,字段数和所有内容都正确,但是
质询的可见字段(
:description
:id
)为空,并且它不会为质询
id
创建隐藏字段!这是怎么回事?我能修好它吗


例子 为id为9的
质询
生成的字段示例,如您所见,非隐藏输入字段没有
,但隐藏id字段有:

    <div class="field">
      <input id="challenge_list_list_joins_attributes_2_challenges_description" name="challenge_list[list_joins_attributes][2][challenges][description]" type="text">
      <input id="challenge_list_list_joins_attributes_2_challenges_id" name="challenge_list[list_joins_attributes][2][challenges][id]" type="text">
      <br>
    </div>
    <!-- This id field is for the join, but there is none for the description... -->
    <input id="challenge_list_list_joins_attributes_2_id" name="challenge_list[list_joins_attributes][2][id]" type="hidden" value="9">  



我想您可能需要一个单一的
挑战:

= links_form.fields_for :challenge do |challenge_form|

查看生成的代码,Rails似乎假定
ListJoin
有许多相关的挑战(例如,
[2][challenges]
),但它只有一个,因为它属于
!这是一只虫子吗?天哪,真不敢相信我竟然对它视而不见。
= form_for @challenge_list do |f|
  -# ...fields for list...
  = f.fields_for :list_joins do |links_form|
     .field
       = links_form.number_field :position
     = links_form.fields_for :challenges do |challenge_form|
       .field
         -# The following fields will be empty
         = challenge_form.text_field :description
         = challenge_form.text_field :id -# Added to test I didn't make a typo on 'description'
    <div class="field">
      <input id="challenge_list_list_joins_attributes_2_challenges_description" name="challenge_list[list_joins_attributes][2][challenges][description]" type="text">
      <input id="challenge_list_list_joins_attributes_2_challenges_id" name="challenge_list[list_joins_attributes][2][challenges][id]" type="text">
      <br>
    </div>
    <!-- This id field is for the join, but there is none for the description... -->
    <input id="challenge_list_list_joins_attributes_2_id" name="challenge_list[list_joins_attributes][2][id]" type="hidden" value="9">  
= links_form.fields_for :challenge do |challenge_form|