Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_eav_model.rb

Instance Method Summary collapse

Instance Method Details

#attributes=(new_attributes, guard_protected_attributes = true) ⇒ Object

Overrides ActiveRecord::Base#attributes=

Because in version >=2.2.2 of ActiveRecord the behaviour in the attributes have been changed to throw a NoMethodError if the AR object don’t respond to an attribute setter, we could not use method missing to allow for our entity-attribute-value behaviour.



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/acts_as_eav_model.rb', line 523

def attributes=(new_attributes, guard_protected_attributes = true)
  return if new_attributes.nil?
  attributes = new_attributes.dup
  attributes.stringify_keys!
  multi_parameter_attributes = []
  attributes = sanitize_for_mass_assignment(attributes) if guard_protected_attributes
  attributes.each do |k, v|
    if k.include?("(")
      multi_parameter_attributes << [ k, v ]
    else
      send(:"#{k}=", v)
    end
  end

  assign_multiparameter_attributes(multi_parameter_attributes)
end