You can also deal with it in the application controller if you do not want to run recovery units on many of your controllers.
Controllers / application _controller.rb
rescue_from ActiveRecord::DeleteRestrictionError do |exception| redirect_to(:back, :alert => exception.message) end
It will redirect the page or resource from which the request came and display a warning message.
source share