Files

Class Index [+]

Quicksearch

ActiveRecord::AttributeMethods::Write

Public Instance Methods

raw_write_attribute(attr_name, value) click to toggle source
Alias for: write_attribute
write_attribute(attr_name, value) click to toggle source

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
Also aliased as: raw_write_attribute

Private Instance Methods

attribute=(attribute_name, value) click to toggle source

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
convert_number_column_value(value) click to toggle source
    # 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
type_cast_attribute_for_write(column, value) click to toggle source
    # File lib/active_record/attribute_methods/write.rb, line 48
48:         def type_cast_attribute_for_write(column, value)
49:           if column && column.number?
50:             convert_number_column_value(value)
51:           else
52:             value
53:           end
54:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.