Module: ActiveRecord::AttributeMethods::Write
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
::ActiveSupport::Concern
|
|
| Defined in: | activerecord/lib/active_record/attribute_methods/write.rb |
Class Method Summary
::ActiveSupport::Concern - Extended
| class_methods | Define class methods from given block. |
| included | Evaluate given block in context of base class, so that you can write class macros here. |
| prepended | Evaluate given block in context of base class, so that you can write class macros here. |
Instance Method Summary
-
#write_attribute(attr_name, value)
Updates the attribute identified by
attr_nameusing the specifiedvalue.
DSL Calls
included
[ GitHub ]9 10 11
# File 'activerecord/lib/active_record/attribute_methods/write.rb', line 9
included do attribute_method_suffix "=", parameters: "value" end
Instance Method Details
#write_attribute(attr_name, value)
Updates the attribute identified by attr_name using the specified value. The attribute value will be type cast upon being read.
# File 'activerecord/lib/active_record/attribute_methods/write.rb', line 31
def write_attribute(attr_name, value) name = attr_name.to_s name = self.class.attribute_aliases[name] || name name = @primary_key if name == "id" && @primary_key @attributes.write_from_user(name, value) end