Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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 链接到删除关联:未定义的方法“新建记录”和x27;零级:零级_Ruby On Rails_Nested Forms_Cocoon Gem - Fatal编程技术网

Ruby on rails 链接到删除关联:未定义的方法“新建记录”和x27;零级:零级

Ruby on rails 链接到删除关联:未定义的方法“新建记录”和x27;零级:零级,ruby-on-rails,nested-forms,cocoon-gem,Ruby On Rails,Nested Forms,Cocoon Gem,我正在尝试用Cocoon构建两个嵌套的表单,效果很好。我有一个游戏模型,有很多问题,一个问题有很多答案 模型 在“回答”字段部分视图中插入指向“删除”关联的链接时出错。我确信这是我的一个错误,但我无法找回我的位置 错误 意见 new.html.erb “游戏/部分/问题域”, 类别:“btn btn次要”, '数据关联插入节点'=>'。包装问题' %> “btn btn主要”%> partials/_question_fields.html.erb 删除该问题 问题 “游戏/部分/答案

我正在尝试用Cocoon构建两个嵌套的表单,效果很好。我有一个游戏模型,有很多问题,一个问题有很多答案

模型 在“回答”字段部分视图中插入指向“删除”关联的链接时出错。我确信这是我的一个错误,但我无法找回我的位置

错误

意见 new.html.erb

“游戏/部分/问题域”,
类别:“btn btn次要”,
'数据关联插入节点'=>'。包装问题'
%>
“btn btn主要”%>
partials/_question_fields.html.erb

删除该问题
问题

“游戏/部分/答案字段”, 数据:{“关联插入方法”=>:prepend}, 类别:“btn btn二级” %>
partials/_answer_fields.html.erb

有人知道我做错了什么吗? 当做
Lilith

partials/\u question\u fields.html.erb

<%= f.fields_for :questions do |answer_form| %>

可能是:

<%= f.fields_for :answers do |answer_form| %>


我们需要看看你在哪里定义链接到移除关联,看看是什么导致了错误就在我问题的最后,在partials/\u answer\u fields.html.erb中,我刚刚看到的最后一个代码插入是一个cocoon方法是的,它是一个coon方法,我从coon文档中复制/粘贴了这行代码。相同的链接在问题\字段部分视图中工作,但当我将此链接放在答案\字段部分复制粘贴问题中时出现错误:/
<%= form_with(model: @game,  url: games_path, local: true ) do |form| %>

  <div class="form-group game">
    <%= form.label(':name', "Title") %>
    <%= form.text_field ':name', class: 'form-control form-control-sm' %>
  </div>

  <div class="wrapper-questions"></div>

  <%= form.fields_for :questions do |question_form| %>
    <%= render 'games/partials/question_fields', f: question_form %>
  <% end %>

  <div class="row form-actions links">
    <div class="col-sm">
      <%= link_to_add_association 'Add a question',
          form,
          :questions,
          :partial => 'games/partials/question_fields',
          class: "btn btn-secondary",
          'data-association-insertion-node' => '.wrapper-questions'
      %>
    </div>

    <div class="col-sm text-right">
      <%= form.submit 'Save', :class => "btn btn-primary" %>
    </div>
  </div>
<% end %>
<div class="question-wrapper jumbotron nested-fields">
  <%= link_to_remove_association f, { class: 'btn btn-light' } do %>
    <i class="fa fa-trash" aria-hidden="true"></i> Delete the question
  <% end %>

  <p><strong>Question</strong></p>

  <div class="form-group">
    <strong><%= f.label(:text, 'Question:') %></strong>
    <%= f.text_field :text, class: "form-control" %>
  </div>

  <%= f.fields_for :questions do |answer_form| %>
    <%= render 'games/partials/answer_fields', f: answer_form %>
  <% end %>

  <div class="row">
    <div id="wrapper-answers"></div>
    <div class="col-sm">
      <%= link_to_add_association 'Add an answer',
          f,
          :answers,
          :partial => 'games/partials/answer_fields',
          data: { 'association-insertion-method' => :prepend },
          class: "btn btn-secondary"
      %>

    </div>
  </div>
</div>
<div class="row nested-fields">
  <div class="col">
    <%= f.text_field :text, class: "form-control" %>
  </div>

  <div class="col">
    <label class="btn btn-secondary form-control">
      <%= f.check_box :correct %>
    </label>
  </div>


  <!-- My error is here -->
  <%= link_to_remove_association 'remove answer', f %>
</div>
<%= f.fields_for :questions do |answer_form| %>
<%= f.fields_for :answers do |answer_form| %>