Set A Timestamp Field To The Current Time
To set a timestamp field to the current time, you could reach for the #update
method like you would when modifying any other field.
This works, but it's more verbose than is necessary and requires that you construct the right timestamp for now (time zones and all).
Rails has a more concise and idomatic way of doing this: #touch
.
Updating a timestamp to the current time is a common action in web applications, so Rails offers the #touch
method as a shorthand for doing it. This will set the given field, in this case :used_at
, to the current time. This will also set the updated_at/on
field.
PreviousSerialize With fast_jsonapi In A Rails AppNextSet default_url_options For Entire Application
Last updated