Tuesday, March 22, 2016

How to handle routing errors in Rails 4.2.6

    Step 1
   
    In routes.rb:
   
    match '*unmatched_route', :to => 'application#handle_routing_error', :via => :all
   
    Step 2
   
In application_controller.rb:

    rescue_from ActionController::RoutingError, :with => :handle_routing_error

    def handle_routing_error
      logger.info "No route matches #{params[:unmatched_route]}"
      render nothing: true
    end

No comments:

Post a Comment