Skip to content

Instantly share code, notes, and snippets.

@virajkulkarni14
Forked from phaex/gist:919326
Last active December 29, 2015 23:58
Show Gist options
  • Save virajkulkarni14/7746038 to your computer and use it in GitHub Desktop.
Save virajkulkarni14/7746038 to your computer and use it in GitHub Desktop.
Rails mass assignment sanitizer
# 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