Skip to content

Instantly share code, notes, and snippets.

@phaex
Created April 14, 2011 11:53
Show Gist options
  • Save phaex/919326 to your computer and use it in GitHub Desktop.
Save phaex/919326 to your computer and use it in GitHub Desktop.
rails 3 mass_assignment_authorizer
# based on Railscast 237, http://railscasts.com/episodes/237-dynamic-attr-accessible
private
# take care of attr_accessible based on user role
def mass_assignment_authorizer
if accessible == :all
# original hack, doesn't work with AR attribute type
# self.class.protected_attributes
# This hack should work as well with AR attribute type
ActiveModel::MassAssignmentSecurity::BlackList.new {:id}
else
super + ( accessible || [] )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment