Sha256: 769d2a37b546b2420492558c854b2d8cefdf23498dd694fe0bfca85319cc4ac6

Contents?: true

Size: 912 Bytes

Versions: 42

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

module ActiveModel
  # = Active \Model \ForbiddenAttributesError
  #
  # Raised when forbidden attributes are used for mass assignment.
  #
  #   class Person < ActiveRecord::Base
  #   end
  #
  #   params = ActionController::Parameters.new(name: 'Bob')
  #   Person.new(params)
  #   # => ActiveModel::ForbiddenAttributesError
  #
  #   params.permit!
  #   Person.new(params)
  #   # => #<Person id: nil, name: "Bob">
  class ForbiddenAttributesError < StandardError
  end

  module ForbiddenAttributesProtection # :nodoc:
    private
      def sanitize_for_mass_assignment(attributes)
        if attributes.respond_to?(:permitted?)
          raise ActiveModel::ForbiddenAttributesError if !attributes.permitted?
          attributes.to_h
        else
          attributes
        end
      end
      alias :sanitize_forbidden_attributes :sanitize_for_mass_assignment
  end
end

Version data entries

42 entries across 42 versions & 6 rubygems

Version Path
activemodel-7.1.0.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-7.1.0.beta1 lib/active_model/forbidden_attributes_protection.rb