我收到了臭名昭著的错误:
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 和accepted_nested_attributes_for,这两个我已经有了。肯定还有别的吗?