Hye,
I try to store DateTime as integer (seconds) in my database (MySQL).
I''d like to convert seconds to DateTime in the ActiveRecord object
to handle it easily in my views.
I try to play with callbacks or with method dedicated to my attributes for eg.
def fetched
upd = nil
v =read_attribute(:fetched)
if (v)
upd = DateTime.at(v)
else
upd = DateTime.now
end
end
def fetched=(y,m,d,h,mn)
v = DateTime.new(y,m,d,h,mn)
write_attribute(:fetched, v.to_i)
end
but I feel it may not be the right way.
How do you think I should handle that ?