Rails: Automatic Time Stamping

I tried this with mySQL. Should work with other databases too.

If you have columns named “created_at” or “updated_at” of type datetime in your database table,
Rails will automatically insert the value of now( ), in the column “created_at” when a model corresponding to the table is saved in the database. Similarly it will automatically update the value of the column “updated_at” to the value of now( ), when a model is updated and saved to the database.

“created_on” and “updated_on”, of type date, display the same functionality.

One of the basic Rails philosophy is “Convention over Configuration”, meaning that rails has sensible defaults for a lot of aspects.

If the programmer follows these naming conventions a lot of functionality in the application gets built-in by default.

Leave a Reply

Your email address will not be published. Required fields are marked *

fifty six − = fifty