This project is archived and is in readonly mode.

#2388 ✓wontfix
azimux

feature patch: config.active_record.raise_on_illegal_mass_assignment option

Reported by azimux | April 1st, 2009 @ 03:15 AM | in 2.x

attr_accessor/attr_protected make it so that values that shouldn't be mass assigned but are present in the passed in hash are ignored. I'd like to have an option to have an exception/error raised in these situation instead of just having it ignored.

The attatched patch allows one to put


config.active_record.raise_on_illegal_mass_assignment = true

into the initializer block of environment.rb and then instead of ignoring bad keys in the hash sent to attributes=/new/create/update_attributes and friends, an IllegalMassAssignmentError will be raised.

Some thoughts: What might be cooler would be to have attr_protected! and attr_accessible! singleton methods on ActiveRecord::Base so that the behavior can be selected at the attribute instead of application level. This would require a slightly more complicated solution since 2 sets of protected/accessible attributes has to be maintained and processed in remove_attributes_protected_from_mass_assignment().

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages