rails: Can no longer rescue_from ActionController::RoutingError

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/4444 Created by Luigi Montanez - 2011-02-14 05:42:01 UTC

In Rails 2.3.x, one is able to stick this in ApplicationController to present the user with a custom 404 screen:

rescue_from(ActionController::RoutingError) { render :text => 'This is a custom 404.' }

Now in Rails 3, because routing is done as middleware (ActionDispatch), it seems that the ActionController::RoutingError that gets thrown by ActionDispatch no longer can be caught from ApplicationController – the error is already thrown and ActionDispatch renders /templates/rescues/routing_error.erb before the controller can rescue_from the error.

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 58 (15 by maintainers)

Commits related to this issue

Most upvoted comments

For those that are using gems that have their own routes: you can also add the catch-all route after initialize to account for that. Just put something like this in application.rb:

    # 404 catch all route
    config.after_initialize do |app|
      app.routes.append{ match '*a', :to => 'application#render_404' } unless config.consider_all_requests_local
    end