Updates the attribute identified by attr_name with the specified value. Empty strings for fixnum and float columns are turned into nil.
# File lib/active_record/attribute_methods/write.rb, line 25 25: def write_attribute(attr_name, value) 26: attr_name = attr_name.to_s 27: attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key 28: @attributes_cache.delete(attr_name) 29: column = column_for_attribute(attr_name) 30: 31: unless column || @attributes.has_key?(attr_name) 32: ActiveSupport::Deprecation.warn( 33: "You're trying to create an attribute `#{attr_name}'. Writing arbitrary " "attributes on a model is deprecated. Please just use `attr_writer` etc." 34: ) 35: end 36: 37: @attributes[attr_name] = type_cast_attribute_for_write(column, value) 38: end
Handle *= for method_missing.
# File lib/active_record/attribute_methods/write.rb, line 44 44: def attribute=(attribute_name, value) 45: write_attribute(attribute_name, value) 46: end
# File lib/active_record/attribute_methods/write.rb, line 56 56: def convert_number_column_value(value) 57: if value == false 58: 0 59: elsif value == true 60: 1 61: elsif value.is_a?(String) && value.blank? 62: nil 63: else 64: value 65: end 66: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.