I have Video and Playlist models. To boost the process of displaying a thumbnail for the Playlist - I've made a column named 'thumbnail'. I would like it to be updated anytime when playlist is updated (because there's a lot of such situations in different parts of my app), so I tried to use callback after_update
:
Class Playlist < ApplicationRecord
after_update :set_thumbnail
def set_thumbnail
video_thumbnail = Video.find(self.content[0]).thumbnail
self.update(thumbnail: video_thumbnail)
end
end
Of course I've got endless cycle.
Rails docs just list methods for skipping callbacks (e.g. decrement, decrement_counter , etc.), so I have no idea how to use them.