Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract nested parameter assignment to a separate method

  • Loading branch information...
commit 5bd96de6253bf45993a80ebc235b64f72b04d902 1 parent 9f88521
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 6 additions and 3 deletions.
  1. +6 −3 activerecord/lib/active_record/attribute_assignment.rb
View
9 activerecord/lib/active_record/attribute_assignment.rb
@@ -104,8 +104,7 @@ def assign_attributes(new_attributes, options = {})
end
end
- # assign any deferred nested attributes after the base attributes have been set
- nested_parameter_attributes.each { |k,v| _assign_attribute(k, v) }
+ assign_nested_parameter_attributes(nested_parameter_attributes) unless nested_parameter_attributes.empty?
assign_multiparameter_attributes(multi_parameter_attributes) unless multi_parameter_attributes.empty?
ensure
@mass_assignment_options = previous_options
@@ -133,6 +132,11 @@ def _assign_attribute(k, v)
end
end
+ # Assign any deferred nested attributes after the base attributes have been set.
+ def assign_nested_parameter_attributes(pairs)
+ pairs.each { |k, v| _assign_attribute(k, v) }
+ end
+
# Instantiates objects for all attribute classes that needs more than one constructor parameter. This is done
# by calling new on the column type or aggregation type (through composed_of) object with these parameters.
# So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate
@@ -252,6 +256,5 @@ def type_cast_attribute_value(multiparameter_name, value)
def find_parameter_position(multiparameter_name)
multiparameter_name.scan(/\(([0-9]*).*\)/).first.first.to_i
end
-
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.