Long story short, each time a user views a resource, an Event model object is created. Each event has a duration column. How can I best save the duration between each event?
class Event
belongs_to :session
end
My gut reaction was to use an after_save callback each time a new event was created, calculate the time between “now” and the previous event, and save that as the previous event’s duration. However, this creates a “waterfall” effect, as the callback is then executed as the previous event is saved, and then the previous before that, and so on.
Any suggestions?
Thanks!
You’d better use after_create callback, this will not trigger while updating previous element