January 12, 2006
Older: Welcome to railstips.org!
Newer: A roundup of the best Rails tutorials
Populating timestamps with ease
I’ll start off the tips with something that I didn’t pay attention to the first time I was putting together a Rails app.
If you have a timestamp or datetime column your database table, you can let ActiveRecord take care of populating it:
> Active Records will automatically record creation and/or update timestamps of database objects if fields of the names created\at/created\on or updated\at/updated\on are present. This module is automatically included, so you don’t need to do that manually.
>
> This behavior can be turned off by setting ActiveRecord::Base.record\
timestamps = false. This behavior can use GMT by setting ActiveRecord::Base.timestamps\
gmt = true
I overlooked this in my first application and named my timestamp columns something like “date_added,” and then had to specify how to set the time. I’ve since learned my lesson!
0 Comments
Thoughts? Do Tell...