Skip to content

Strong Parameters and Rails 3 #60

Closed
@leonelgalan

Description

@leonelgalan

After setting config.whitelist_attributes = false in application.rb, the model that is acting as a tree raises ActiveModel::MassAssignmentSecurity::Error. This is, because closure_tree is adding attr_accessible :parent (https://github.com/mceachen/closure_tree/blob/32da850126336fec6036ad8154a9b1fa738cb30e/lib/closure_tree/model.rb#L17)

https://github.com/mceachen/closure_tree/blob/32da850126336fec6036ad8154a9b1fa738cb30e/lib/closure_tree/support.rb#L23

    def use_attr_accessible?
      ActiveRecord::VERSION::MAJOR == 3 &&
        defined?(ActiveModel::MassAssignmentSecurity) &&
        model_class.ancestors.include?(ActiveModel::MassAssignmentSecurity)
    end

I beleive that this happens because of the last condition of use_attr_accessible?, which returns true even when using strong parameters. A better condition will be model_class.accessible_attributes.empty?, which returns true only when attr_accessible has been used in the model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions