Setting up Rails 3 config for attr_accessible / protected

I've spent quite a lot of time solving the problem with virtual attributes in my model. It turned out I just forgot to add it to attr_accesible in my model. Of course I should have caught this sooner or better, should have started the whole thing by adding it to attr_accessible first.

To prevent this from happening again, is there a config option that I can specify to throw an exception while developing if I try to assign something and check it when it's protected / unavailable? I know I can use set config.active_record.whitelist_attributes = true

to require a whitelist for everyone, but my question is more based on an individual attribute.

The above line, for example, doesn't alert me if I have a model with attr_accessible: name, then add: nickname (virtual or not) and try assigning it to check for presence => true. I want it to alert me that I was trying to validate a protected attribute using bulk assignment.

+3


source to share


1 answer


Rails 3.2 has a config option to boost ActiveModel::MassAssignmentSecurity::Error

in this case

config.active_record.mass_assignment_sanitizer = :strict



See the Rails 3.2 release notes and the commit in Rails

+6


source







All Articles