这是代码:
用户.rb
class User < ActiveRecord::Base
# So we can reference the user's Client information with user.as_client
has_one :as_client, :class_name => 'ClientAccount'
accepts_nested_attributes_for :as_client
end
form.html.erb
<%= f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.fields_for :as_client do |c| %>
<%= c.label :website %>
<%= c.text_field :website %>
<%= end %>
现在,当我提交表单时,会发送以下内容:
{"user"=>{"first_name"=>"Name", "as_client_attributes"=> "website"=>"http://website.com"}}, "commit"=>"Update User"}
我得到这个错误:
Can't mass-assign protected attributes: as_client_attributes
我怎样才能使这项工作?谢谢!