Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 688 Bytes

rescue-from.md

File metadata and controls

21 lines (17 loc) · 688 Bytes

Rescue From

The rescue_from method, provided by ActiveSupport, is a handy way to provide a catch-all response to a particular exception in Rails controllers.

For instance, if many of the controllers in your application raise a User::NotAuthorized error for unauthorized requests, the ApplicationController can provide a unified response. This will help dry up your controllers and prevent any potential inconsistencies.

class ApplicationController < ActionController::Base
  rescue_from User::NotAuthorized do |exception|
    # respond with some Not Authorized page
  end

  ...
end