Displaying 1 result from an estimated 1 matches for "my_date_parser".
2007 Mar 30
1
write attribute coming from where?
...post.date = "22-jan-2007"
puts post.date
you get a nil instead of a Date object, because
ActiveRecord::Base::Column#type_cast is called by the getter via
read_attribute, who does not understand that string.
Another approach is to redefine the setter:
def date=(v)
v = my_date_parser(v) if v.is_a?(String)
write_attribute(:date, v)
end
but that breaks objet loading from the database because that setter
is called by the database adapter as well, and going in that
direction my_date_parser receives a String with the format used by
the database.
I think having a cust...