In my app, users have one location, and locations belong to users.
user.rb
has_one :location
accepts_nested_attributes_for :location
attr_accessible ... :location_attributes
location.rb
belongs_to :user
attr_accessible :country, :state, :city, :address, :zipcode, :user_id
users_controller (users are auto-created, so there is no "new" view)
def edit
@user = current_user
@user.build_location
end
users/edit.html.haml
= form_for @user do |f|
...
= f.fields_for :location do |location|
%p
= location.label :country
= location.text_field :country
%p
= location.label :state
= location.text_field :state
%p
= location.label :city
= location.text_field :city
%p
= location.label :address
= location.text_field :address
%p
= location.label :zipcode
= location.text_field :zipcode
= f.submit
The error I'm getting is "Can't Mass Assign Protected Attributes: country, state, city, address, zipcode."
I've gotten the "Can't Mass Assign Protected Attributes: location_attribute" type of error before, but that's not the problem here.
Here are my (abridged) params:
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"RTpnMsKuByhnGgs9xrX3d0nzKzcaqIcpS75tsujPX2s=", "user"=>{"name"=>"myname", ... "location_attributes"=>{"country"=>"USA", "state"=>"whatever", "city"=>"", "address"=>"", "zipcode"=>""}}, "commit"=>"Update account", "action"=>"update", "controller"=>"users", "id"=>"219"}
Any idea what's going on here? I've searched for a WHILE, and can't seem to find anyone with this problem (everyone else has the latter mass-assign one).