Ruby on rails 3.2 嵌套表单字段

Ruby on rails 3.2 嵌套表单字段,ruby-on-rails-3.2,Ruby On Rails 3.2,我使用了Ryan Bates railscast教程来制作这个。但我遇到了一个问题,我试着效仿他的做法,但没有成功 第一部分是让我的Projects表访问问卷属性 class Project < ActiveRecord::Base attr_accessible :pid, :name, :qheader, :questionaires_attributes has_many :questionaires accepts_nested_attributes_for :questio

我使用了Ryan Bates railscast教程来制作这个。但我遇到了一个问题,我试着效仿他的做法,但没有成功

第一部分是让我的Projects表访问问卷属性

class Project < ActiveRecord::Base
 attr_accessible :pid, :name, :qheader, :questionaires_attributes
 has_many :questionaires
 accepts_nested_attributes_for :questionaires, allow_destroy: true

 pid_regex = /\d+/

 validates :pid, presence: true, format: { with: pid_regex}, uniqueness: true
 validates :name, presence: true
 # validates :qheader, presence: true

end
class项目
我对我的问卷模型也做了同样的事情,请忽略问卷拼写错误的事实,因为我已经检查了所有地方,以确保其拼写相同

class Questionaire < ActiveRecord::Base
 attr_accessible :content, :project_id
 belongs_to :project
end
class问卷
然后,我为视图/项目构建了new.html.erb

<%= form_for @project do |f| %>
 <%= render 'shared/error_msgs' %>
 <div class="field">
  <%= f.label :pid %><br />
  <%= f.text_field :pid %>
 </div>
 <div class="field">
  <%= f.label :name %><br />
  <%= f.text_field :name %>
 </div>
 <%= f.fields_for :questionaires do |builder| %>
   <%= render "questions", f: builder %>
 <% end %>

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



根据Ryan Bates的说法,从我所看到的情况来看

 <%= f.fields_for :questionaires do |builder| %>

应为复数,但当为复数时,位于渲染部分的字段集将消失,但当:问号为单数时,字段集将重新出现。但如果我提交它,它会告诉我它不能批量分配给受保护的属性:问号


谁能告诉我怎么修这个吗

我发现它有什么毛病。只是我的名字不好。该部分应命名为问询_字段,但缺少添加新问询字段的按钮。它现在正在工作。包括验证