Ruby on rails 嵌套形式的质量赋值
我正在关注railscasts 196集,我尝试了他所做的一切,但我犯了以下错误Ruby on rails 嵌套形式的质量赋值,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,我正在关注railscasts 196集,我尝试了他所做的一切,但我犯了以下错误 ActiveModel::MassAssignmentSecurity::Error in SurveysController#create Can't mass-assign protected attributes: questions_attributes Rails.root: /home/jean/rail/surveysays 这是到目前为止我的代码 调查表 <%= form_for(@surv
ActiveModel::MassAssignmentSecurity::Error in SurveysController#create
Can't mass-assign protected attributes: questions_attributes
Rails.root: /home/jean/rail/surveysays
这是到目前为止我的代码
调查表
<%= form_for(@survey) do |f| %>
<% if @survey.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@survey.errors.count, "error") %> prohibited this survey from being saved:</h2>
<ul>
<% @survey.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<%= f.fields_for :questions do |bf|%>
<%= bf.label :content, "Question" %><br />
<%= bf.text_area :content, :rows=> 3 %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
把你的课改成这个
class Survey < ActiveRecord::Base
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions
attr_accessible :name, :questions_attributes
end
有关详细信息,请查找主题使用with attr_accessible
class Survey < ActiveRecord::Base
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions
attr_accessible :name, :questions_attributes
end
查找使用attr_访问的主题以获取更多信息它工作正常,我在另外6分钟内无法接受答案,同时这是ruby的新功能吗?它工作正常,我在另外6分钟内无法接受答案,同时这是ruby的新功能吗?
def new
@survey = Survey.new
3.times {@survey.questions.build }
respond_to do |format|
format.html # new.html.erb
format.json { render json: @survey }
end
end
class Survey < ActiveRecord::Base
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions
attr_accessible :name, :questions_attributes
end