Before Type Cast - 类型转换
read_attribute_before_type_cast
x_before_type_cast
attributes_before_type_castclass Task < ActiveRecord::Base
end
task.read_attribute('id') # => 1
task.read_attribute_before_type_cast('id') # => '1'
task.read_attribute('completed_on') # => Sun, 21 Oct 2012
task.read_attribute_before_type_cast('completed_on') # => "2012-10-21"
task.completed_on_before_type_cast('completed_on') # => "2012-10-21"
task.attributes
# => {"id"=>nil, "title"=>nil, "is_done"=>true, "completed_on"=>Sun, 21 Oct 2012,
"created_at"=>nil, "updated_at"=>nil}
task.attributes_before_type_cast
# => {"id"=>nil, "title"=>nil, "is_done"=>true, "completed_on"=>"2012-10-21",
"created_at"=>nil, "updated_at"=>nil}最后更新于