instance method
assign_attributes
Ruby on Rails 4.0.13
Since v3.2.22.5 Last seen in v4.2.9Signature
assign_attributes(new_attributes)
Allows you to set all the attributes by passing in a hash of attributes with keys matching the attribute names (which again matches the column names).
If the passed hash responds to permitted? method and the return value of this method is false an ActiveModel::ForbiddenAttributesError exception is raised.
Parameters
-
new_attributesreq
Source
# File activerecord/lib/active_record/attribute_assignment.rb, line 14
def assign_attributes(new_attributes)
return if new_attributes.blank?
attributes = new_attributes.stringify_keys
multi_parameter_attributes = []
nested_parameter_attributes = []
attributes = sanitize_for_mass_assignment(attributes)
attributes.each do |k, v|
if k.include?("(")
multi_parameter_attributes << [ k, v ]
elsif v.is_a?(Hash)
nested_parameter_attributes << [ k, v ]
else
_assign_attribute(k, v)
end
end
assign_nested_parameter_attributes(nested_parameter_attributes) unless nested_parameter_attributes.empty?
assign_multiparameter_attributes(multi_parameter_attributes) unless multi_parameter_attributes.empty?
end
Defined in activerecord/lib/active_record/attribute_assignment.rb line 14
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::AttributeAssignment