Cette méthode est la responsable de la type_cast
dans le dossier actif
def type_cast(value)
return nil if value.nil?
return coder.load(value) if encoded?
klass = self.class
case type
when :string, :text then value
when :integer then klass.value_to_integer(value)
when :float then value.to_f
when :decimal then klass.value_to_decimal(value)
when :datetime, :timestamp then klass.string_to_time(value)
when :time then klass.string_to_dummy_time(value)
when :date then klass.value_to_date(value)
when :binary then klass.binary_to_string(value)
when :boolean then klass.value_to_boolean(value)
else value
end
end
Pour comprendre rails
activerecord
type_cast
en détail s'il vous plaît visiter ces trois sites
1) Blog Thoughtbot How Rails' Type Casting Works
2) Ken Collins ActiveRecord 4.2's Type Casting
3) Rails activerecord
méthode cataloguée en github