method
write_attribute_with_type_cast
v4.1.8 -
Show latest stable
-
0 notes -
Class: ActiveRecord::AttributeMethods::Write
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
write_attribute_with_type_cast(attr_name, value, type_cast_method)
private
Hide source
# File activerecord/lib/active_record/attribute_methods/write.rb, line 78 def write_attribute_with_type_cast(attr_name, value, type_cast_method) attr_name = attr_name.to_s attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key @attributes_cache.delete(attr_name) column = column_for_attribute(attr_name) # If we're dealing with a binary column, write the data to the cache # so we don't attempt to typecast multiple times. if column && column.binary? @attributes_cache[attr_name] = value end if column || @attributes.has_key?(attr_name) @attributes[attr_name] = send(type_cast_method, column, value) else raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'" end end