Type:
Module

Active Record Attribute Methods Before Type Cast

ActiveRecord::AttributeMethods::BeforeTypeCast provides a way to read the value of the attributes before typecasting and deserialization.

class Task < ActiveRecord::Base
end

task = Task.new(id: '1', completed_on: '2012-10-21')
task.id           # => 1
task.completed_on # => Sun, 21 Oct 2012

task.attributes_before_type_cast
# => {"id"=>"1", "completed_on"=>"2012-10-21", ... }
task.read_attribute_before_type_cast('id')           # => "1"
task.read_attribute_before_type_cast('completed_on') # => "2012-10-21"

In addition to read_attribute_before_type_cast and attributes_before_type_cast, it declares a method for all attributes with the *_before_type_cast suffix.

task.id_before_type_cast           # => "1"
task.completed_on_before_type_cast # => "2012-10-21"
attributes_before_type_cast

attributes_before_type_cast() Instance Public methods Returns a hash of attributes

2015-06-20 00:00:00
read_attribute_before_type_cast

read_attribute_before_type_cast(attr_name) Instance Public methods Returns the

2015-06-20 00:00:00