RE: how to insert Current DateTime value into database?


#1

If you simply want the time that a record was updated, simply add a
field to the model table called “updated_at”. It’ll auto-update on save.


#2

It’s not rails-y, but I like having the db take care of this. If you’re
using migration maybe it doesn’t matter, but if you’re defining your
tables
first, then you could define them like so.

updated TIMESTAMPTZ NOT NULL DEFAULT NOW(),

– TIMESTAMPTZ is postgresql-specific I believe.

This covers you if you have ever have non-ruby/rails updates to the
table.

Is this basically what rails does under the covers?

thanks.