I have a 2-level nested models:
country <- state <- city
Currently, in each controller, upon all CRUD operation, I will find its parent model and runs the .touch for each model. For example:
# cities_controller.rb
def update
@state = State.find(params[:state_id])
@country = Country.find(@state.id)
...
@state.touch
@country.touch
end
For each action in state, city, I would touch its parent (and its parent’s parent) whenever CRUD is completed successfully.
Is there any DRYer way to do this? I know about autosave option, but it only works for newly created associated record. I want to include destroyed, updated record also. If one city is changed, it’s state and country will also be timestamped to reflect something has been changed.
Many thanks.
If I were you, I prefer to rewrite the
touchfunction in this there models.