Sha256: 2612dc1429290d4bd2559d429cf08fad0a18b0006c8f77b42cb11e4df26ab1df

Contents?: true

Size: 831 Bytes

Versions: 22

Compression:

Stored size: 831 Bytes

Contents

module ActiveModel
  # 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

22 entries across 22 versions & 2 rubygems

Version Path
activemodel-5.1.7 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.7.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.6.2 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.6.1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.6 lib/active_model/forbidden_attributes_protection.rb
tdiary-5.0.8 vendor/bundle/gems/activemodel-5.1.5/lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.5 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.5.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.4 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.4.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.3 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.3.rc3 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.3.rc2 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.3.rc1 lib/active_model/forbidden_attributes_protection.rb
tdiary-5.0.5 vendor/bundle/gems/activemodel-5.1.2/lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.2 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.2.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.0 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.1.0.rc2 lib/active_model/forbidden_attributes_protection.rb