MassAssignment
MassAssignment allows you to bulk set and update attributes
Including MassAssignment into your model gives it a set of mass assignment
methods, similar to those found in ActiveRecord.
Originally part of ActiveAttr, https://github.com/cgriego/active_attr
Constants
Methods
- #assign_attributes
Mass update a model’s attributes
def assign_attributes(new_attributes = nil)
return unless new_attributes.present?
new_attributes.each do |name, value|
writer = :"#{name}="
send(writer, value) if respond_to?(writer)
end
end
- #attributes=
Mass update a model’s attributes
def attributes=(new_attributes)
assign_attributes(new_attributes)
end
- #initialize
Initialize a model with a set of attributes
def initialize(attributes = nil)
assign_attributes(attributes)
super()
end