I want to do something like this:
MyController < ApplicationController
rescue_from ActiveRecord::StaleObjectError, :retry
I have an app where users and admins are occasionally updating the same object at the same time and they sometimes collide. The actions are fairly short lived and should succeed on a retry, so it would be great to try without involving the client.
It would be OK if this happened at another layer in the stack too. Somewhere in Rack perhaps?
I looked for retry methods in the Rails API and didn't find anything. My internet searches and Rails discussion searches were also fruitless. I could, of course, put code in the controller like the following, but I'd like to do it for all the actions I have without duplicating that everywhere.
def myaction
# do stuff
rescue ActiveRecord::StaleObjectError
retry
end
You can try below
I hope this will help you. Reference