Skip to content

Instantly share code, notes, and snippets.

@dv
Created December 10, 2015 16:34
Show Gist options
  • Save dv/973f7361733091828c6e to your computer and use it in GitHub Desktop.
Save dv/973f7361733091828c6e to your computer and use it in GitHub Desktop.
For when you're in between mass-assignment and strong-params
module ActiveModel
module MassAssignmentSecurity
# Original source: https://github.com/rails/protected_attributes/blob/0421e825911b05a77c6521171b43070c9e6c4b35/lib/active_model/mass_assignment_security.rb#L350
def sanitize_for_mass_assignment(attributes, role = nil) #:nodoc:
if attributes.respond_to?(:permitted?) && _uses_mass_assignment_security
_mass_assignment_sanitizer.sanitize(self.class, attributes, mass_assignment_authorizer(role))
else
sanitize_forbidden_attributes(attributes)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment