0
我得到了臭名昭著的错误:据我所知道的,我所做的一切,就在我的模型的Rails 3:无法大规模分配嵌套属性
Can't mass-assign protected attributes: comments
:
class Book < ActiveRecord::Base
attr_accessible :author, :edition, :issue, :title, :url, :comments_attributes
has_many :comments, :dependent => :destroy
accepts_nested_attributes_for :comments, :allow_destroy => true
end
并查看:
<%= form_for @book, :remote => true do |f| %>
<%= f.label :title %>:
<%= f.text_field :title %><br />
<%= f.label :author %>:
<%= f.text_field :author %><br />
<%= f.fields_for @comment do |comment| %>
<%= comment.label :body, :Comment %>:
<%= comment.text_area :body %><br />
<% end %>
<%= f.submit %>
<% end %>
缺少什么我在这里?我已经读过了关于stackoverflow的十几个类似的问题,但唯一的建议似乎是添加attr_accessible和acceptered_attributes_for,这两个我已经有了。当然还有别的吗?
在一次绝望的尝试中,我试着把'has_many'声明置于顶层,在attr_accessible声明之前... –
有趣的想法,但不幸的是,仍然没有运气。 – nullnullnull
在Comment类中,你是否声明'attr_accessible:body'可能? –