Auto set value for a model field

Hello,

I have a model - Post with datetime field <added_at>. I need to set this
value to time when in created or when it updated automatically.

Thanks

I have a model - Post with datetime field <added_at>. I need to set this
value to time when in created or when it updated automatically.

Why not use the fields created_at and updated_at and let Rails do this
for
you?

Why not use the fields created_at and updated_at and let Rails do this
for
you?

Hello,

Thanks fro reply.

How to do it?

Hi Igor

Philip is right.Just add
created_at or created_on
updated_at or updated_on

in your table.

That’s it :slight_smile:

On Oct 11, 2:56 pm, “Igor K.” [email protected]

I tried it - and i think i can use onle updated_at field.

Thanks

Philip is right.Just add
created_at or created_on
updated_at or updated_on

in your table.

But I don’t need a two columns for this. I want to have one field that
contain datetime when it last time modified of created.

Thanks for reply

Hi Igor

Being opinionated,Rails had already decided on auto-updating on create
and on update separately :slight_smile:

On Oct 11, 5:16 pm, “Igor K.” [email protected]