hi all: I have met the "Can't mass-assign protected attributes: " problem. I have two models. one is province
class Province < ActiveRecord::Base attr_accessible :name has_many :cities accepts_nested_attributes_for :cities end
and another is city class City < ActiveRecord::Base attr_accessible :name,:province_id belongs_to :province has_many :districts end
when I created the city instant by @city=City.new(params[:city]). It works but when I updated it using: @city=City.find(params[:id]) flash[:notice]="error cannot update information of the city" if @city.update_attributes(params[:city])
I got "Can't mass-assign protected attributes: province_id"
I image that the reason new works is that you are not assigning provice_id using update_attributes. Is the code for class City that you posted above copied and pasted from the source or did you re-type it? Can you copy/paste the full error message please and also the bit from development.log for the failing action. Also the code for that action from the controller.
Also check that you have not accidentally left any files in the model folder that should not be there - a copy of an old version of city.rb for example.