August 2025
Intermediate to advanced
294 pages
6h 59m
English
We’ve been using some built-in changes already in Tunez, without even realizing it, for inserted_at and updated_at timestamps on our resources. We didn’t write any code for them, but Ash takes care of setting them to the current time. Both timestamps are set when calling any create action, and updated_at is set when calling any update action.
Like validations, changes can be defined at both the top level of a resource and at an individual action level. The implementation for timestamps could look like this:
| | changes do |
| | change set_attribute(:inserted_at, &DateTime.utc_now/0), on: [:create] |
| | change set_attribute(:updated_at, &DateTime.utc_now/0) |
| | end |
|
By default, global changes will run on any |
Read now
Unlock full access