Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

feature patch: config.active_record.raise_on_illegal_mass_assignment option

#2388

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().

Reported by azimux · April 1st, 2009 @ 03:15 AM

State: wontfix
Milestone: 2.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to Jeremy Kemper
    • State changed from new to wontfix

    We've had this feature before, but it has since been reverted. I think it's probably a better fit for a plugin. Assigning to Jeremy as he may have more to add.

    May 17th, 2009 @ 07:48 PM

  2. Paul Alexander