Rails and attr_*

There is a small gotcha in rails attr_accessible method in ruby.

  • If there are no attr_accessible attributes on a model it’s open, any attribute can be written with .update_attributes() or a similar mass-assignment function.
  • If there is even one attr_accessible the model is closed except for those attributes defined to be attr_accessible.

So there is an implicit toggle involved in attr_accessible as well as the actual desired functionality of allowing an attribute to be mass-assigned

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s