Module: ActiveAttr::MassAssignment
- Extended by:
- ActiveSupport::Concern
- Includes:
- ChainableInitialization
- Included in:
- Model, Serialization
- Defined in:
- lib/active_attr/mass_assignment.rb
Overview
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.
Instance Method Summary collapse
-
#assign_attributes(new_attributes, options = {}) ⇒ Object
Mass update a model’s attributes.
-
#attributes=(new_attributes) ⇒ Object
Mass update a model’s attributes.
-
#initialize(attributes = nil, options = {}) ⇒ Object
Initialize a model with a set of attributes.
Instance Method Details
#assign_attributes(new_attributes, options = {}) ⇒ Object
Mass update a model’s attributes
36 37 38 39 40 41 42 43 |
# File 'lib/active_attr/mass_assignment.rb', line 36 def assign_attributes(new_attributes, ={}) sanitized_new_attributes = sanitize_for_mass_assignment_if_sanitizer new_attributes, sanitized_new_attributes.each do |name, value| writer = "#{name}=" send writer, value if respond_to? writer end if sanitized_new_attributes end |
#attributes=(new_attributes) ⇒ Object
Mass update a model’s attributes
55 56 57 |
# File 'lib/active_attr/mass_assignment.rb', line 55 def attributes=(new_attributes) assign_attributes new_attributes end |
#initialize(attributes = nil, options = {}) ⇒ Object
Initialize a model with a set of attributes
69 70 71 72 |
# File 'lib/active_attr/mass_assignment.rb', line 69 def initialize(attributes=nil, ={}) assign_attributes attributes, super end |