Module: DynamicActiveModel::DangerousAttributesPatch

Defined in:
lib/dynamic-active-model/dangerous_attributes_patch.rb

Overview

DynamicActiveModel::DangerousAttributesPatch is used to remove dangerous attribute names from attribute_names method in ActiveRecord

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dynamic-active-model/dangerous_attributes_patch.rb', line 7

def self.included(base)
  return unless base.attribute_names

  columns_to_ignore = base.columns.select do |column|
    if column.type == :boolean
      base.dangerous_attribute_method?(column.name) ||
        base.dangerous_attribute_method?("#{column.name}?")
    else
      base.dangerous_attribute_method?(column.name)
    end
  end
  base.ignored_columns = columns_to_ignore.map(&:name)
end