Created
April 14, 2011 11:53
-
-
Save phaex/919326 to your computer and use it in GitHub Desktop.
rails 3 mass_assignment_authorizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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