Sha256: ca7f881a4351edb05fd8fecaeb82c11b06c339e9a643a9a939a98e8cf704e9f4

Contents?: true

Size: 833 Bytes

Versions: 38

Compression:

Stored size: 833 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:
    protected
      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

38 entries across 37 versions & 5 rubygems

Version Path
activemodel-5.0.7.2 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.7.1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.7 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.6 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.6.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.5 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.5.rc2 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.5.rc1 lib/active_model/forbidden_attributes_protection.rb
tdiary-5.0.5 vendor/bundle/gems/activemodel-5.0.2/lib/active_model/forbidden_attributes_protection.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activemodel-5.0.2/lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.4 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.4.rc1 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.3 lib/active_model/forbidden_attributes_protection.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activemodel-5.0.2/lib/active_model/forbidden_attributes_protection.rb
tdiary-5.0.4 vendor/bundle/gems/activemodel-5.0.2/lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.2 lib/active_model/forbidden_attributes_protection.rb
activemodel-5.0.2.rc1 lib/active_model/forbidden_attributes_protection.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/forbidden_attributes_protection.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/forbidden_attributes_protection.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/forbidden_attributes_protection.rb