Is there a way in Ruby or Rails to have a global exception handler to rescue from a StaleObject exception? I know about rescue_action_in_public, but I don’t know how to get the object the exception occurred on.
For example, while updating a record identified as @my_record, a StaleObject exception is thrown. I would like to implement a global way of grabbing the class variable in the exception handling and automatically comparing all the attributes from params[:my_record] to @my_record.
If the record has become stale on attributes that weren’t changed by the user (i.e. user 1 changed field “title”, while user 2 only changed field “summary”), although the record has become stale, updating the record with the updated fields on the newer version of the record doesn’t need additional user intervention. If the attributes changed by both users are identical, it would be handled differently.
I know I’m simplifying things a bit, but I think you pretty much get the picture.
I just want to avoid having to repeat myself all the time:
Peter De Berdt