In Rails 5, when a callback needs to cancel later callbacks, the recommended process is documented as "you should explicitly throw :abort
."
My question is: how is it recommended that this exception be caught?
My current solution is to catch UncaughtThrowError
in my ApplicationController
- given the way it's documented, I thought this feature would trigger some magic in Rails or a Rack middleware to immediately move to the rendering (ActionView
) phase.
Here are some examples of how to use the throw/catch in ruby.
For Rails, I think something like this will do the trick:
class SomeController
def some_method
if catch(:abort) { mode.save }
# success
else
# failure
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With