我错过了一个需要被允许的属性

时间:2016-08-25 20:26:22

标签: ruby-on-rails nested-attributes

我知道我错过了什么,但我无法弄清楚是什么。

它非常嵌套。我有一个测验,其中有许多问题,有很多答案。答案belongs_to属于测验的问题。

到目前为止我所拥有的:

params.require(:quiz).permit(:name, questions_attributes: [:content, :quiz_id, :explanation, :passage, answers_attributes: [:content, :question_id, :correct_answer]])

我的表格:

<%= form_for(@quiz) do |f| %>
  <% if @quiz.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@quiz.errors.count, "error") %> prohibited this quiz from being saved:</h2>

      <ul>
      <% @quiz.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
    <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>


    <%= f.fields_for :questions do |question_attribute| %>
    <div class = 'inner-c'>
   <p>
    <%= question_attribute.label :content, "Question" %>    <span><b><%= question_attribute.index + 1 %></b></span> <br/> 
    <%= question_attribute.text_area :content, :cols => 100, :rows => 4 %>
    </p>
    <p>
    <%= question_attribute.label :explanation, "Answer Explanation" %> <br/>
    <%= question_attribute.text_area :explanation, :cols => 100, :rows => 6 %>

</p>
    <%= question_attribute.label :_destroy, "Remove Question"%> 
    <%= question_attribute.check_box :_destroy %><br/>

    <%= question_attribute.label :passage, "Reference Passage" %> <br/>
    <%= question_attribute.text_area :passage, :rows => 3, :class => 'passage-input' %>


    <%#= question_attribute.label :question_explanation, "Question Explanation" %>
    <%#= question_attribute.text_area :question_explanation, :rows => 10 %>


  </p>

   <%= question_attribute.fields_for :answers do |answer_attribute| %>
    <p>
      <%= answer_attribute.label :content, "Answer" %>
      <%= answer_attribute.text_field :content %>
      <%= answer_attribute.label :correct_answer, "Check to indicate correct answer", :class => 'inline' %>
      <%= answer_attribute.check_box :correct_answer, :class => 'inline'%>

    </p>
   <% end %> 

   </div> <!-- inner-c -->
 <% end %> 


  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

0 个答案:

没有答案