Method: Cms::Behaviors::DynamicAttributes::InstanceMethods#assign_attributes

Defined in:
lib/cms/behaviors/dynamic_attributes.rb

#assign_attributes(new_attributes, options = {}) ⇒ Object

Overrides the assign_attributes= defined in ActiveRecord::Base(active_record/base.rb)

The only difference is that this doesn’t check to see if the model responds_to the method before sending it

Not happy with this copy/paste duplication, but its merely an update to the previous Rails 2/3 behavior Must remain PUBLIC so other rails methods can call it (like ActiveRecord::Persistence#update_attributes)



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/cms/behaviors/dynamic_attributes.rb', line 232

def assign_attributes(new_attributes, options = {})
  return unless new_attributes

  attributes = new_attributes.stringify_keys
  role = options[:as] || :default

  multi_parameter_attributes = []

  # Disabling mass assignment protection for attributes, might be a terrible idea, but dynamic_attributes are really wonky.
  #unless options[:without_protection]
  #  attributes = sanitize_for_mass_assignment(attributes, role)
  #end

  attributes.each do |k, v|
    if k.include?("(")
      multi_parameter_attributes << [k, v]
    else
      # Dynamic Attributes will take ALL setters (unlike ActiveRecord)
      send("#{k}=", v)
    end
  end

  assign_multiparameter_attributes(multi_parameter_attributes)
end