instance method write_attribute

Ruby on Rails 3.1.12

Since v3.0.20 Last seen in v3.2.22.5 Private

Available in: v3.0.20 v3.1.12 v3.2.22.5

Signature

write_attribute(attr, value)

Wrap write_attribute to remember original attribute value.

Parameters

attr req
value req
Source
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 52
      def write_attribute(attr, value)
        attr = attr.to_s

        # The attribute already has an unsaved change.
        if attribute_changed?(attr)
          old = @changed_attributes[attr]
          @changed_attributes.delete(attr) unless field_changed?(attr, old, value)
        else
          old = clone_attribute_value(:read_attribute, attr)
          # Save Time objects as TimeWithZone if time_zone_aware_attributes == true
          old = old.in_time_zone if clone_with_time_zone_conversion_attribute?(attr, old)
          @changed_attributes[attr] = old if field_changed?(attr, old, value)
        end

        # Carry on.
        super(attr, value)
      end

Defined in activerecord/lib/active_record/attribute_methods/dirty.rb line 52 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::AttributeMethods::Dirty

Type at least 2 characters to search.

↑↓ navigate · open · esc close