timestamp - automatically inserting

Hi:

I have timestamps in virtually all of my tables. The timestamp I want to add is always the current time, whenever I create a record in a table. Is this the type of thing I can be setting in my models, without have to be worrying about it in my controller methods. And if so, how would i do that in the model?

Any help you can provide would be appreciated! Thanks!

Mike

If you include a datetime column called created_at, it will automatically be populated. Ditto for modified_at.

Miked wrote:

I have timestamps in virtually all of my tables. The timestamp I want to add is always the current time, whenever I create a record in a table. Is this the type of thing I can be setting in my models, without have to be worrying about it in my controller methods. And if so, how would i do that in the model?

Any help you can provide would be appreciated! Thanks!

If you have a field in your database table named updated_at that is :datetime, rails will automatically do it for you and you don't need to do anything else anywhere. Similarly for created_at

I'm sure there's a way in your model to tell Rails to use a different column than updated_at, but search for updated_at for more details.

Just:   add_column :my_table, :created_at, :datetime

to each table and let ActiveRecord to the rest.

You can also use updated_at to see modification times. If you want the date only, created_on/updated_on are the way to go.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com