The best way to catch: interrupt signal to the Rails 5 controller

In Rails 5, when a callback should cancel subsequent callbacks, the recommended process is documented as "you must explicitly throw :abort ".

My question is: how is it recommended to eliminate this exception?

My current solution is to catch an UncaughtThrowError in my ApplicationController - given the way it is documented, I thought this function would call some magic in Rails or Rack middleware to go directly to the rendering stage ( ActionView ).

+5
source share
1 answer

Here are some examples of using 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 
0
source

Source: https://habr.com/ru/post/1263545/


All Articles