0

From the docs, I see that if I have a model:

User has_many Addresses 

that I can do this:

class User < AR::Base attr_accessible :addresses_attributes accepts_nested_attributes_for :addresses end 

that I should be able to set those attributes from User. But I can't. Do I also need to add an "attr_accessible" callout in the Address model?

1 Answer 1

1

Yes, you have to set attr_accessible on the Address model as well.

When ActiveRecord initializes an instance using a hash of attributes it will throw an exception when an attribute which has not been marked by attr_accessible is a part of the hash keys. Since in associations ActiveRecord objects are initialized with a hash of attributes there's no escaping from stating those attributes inside the Address model with attr_accessible.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.