Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:13:42+00:00 2026-06-02T18:13:42+00:00

Rails 3 seems is ignoring my rescue_from handler so I cannot test my redirect

  • 0

Rails 3 seems is ignoring my rescue_from handler so I cannot test my redirect below.

class ApplicationController < ActionController::Base

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

  def rescue_404
    flash[:notice] = "Error 404. The url <i>'#{env["vidibus-routing_error.request_uri"]}'</i> does not exist on this website."
    redirect_to root_path
  end
end

In both functional and integration tests, this rescue_from is ignored, and the error is raised:

ActionController::RoutingError: No route matches "/non_existent_url"
    test/integration/custom_404_test.rb:5:in `test_404'

How can I make sure this is properly ‘caught’ in a test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:13:44+00:00Added an answer on June 2, 2026 at 6:13 pm

    Rails 3 handles ActionController::RoutingError in middleware, so ApplicationController::rescue_from doesn’t see the exception. The Rails core team recommends using a catch-all route at the bottom of routes.rb (GitHub issue) until they decide on a fix.

    One option is to use a catch-all route to handle routing errors then manually raise an exception to hit rescue_from (code from my blog post about this issue):

    # routes.rb
    match "*path", :to => "application#routing_error"
    
    # application_controller.rb
    rescue_from ActionController::RoutingError, :with => :render_not_found
    
    def routing_error
      raise ActionController::RoutingError.new(params[:path])
    end
    
    def render_not_found
      render :template => "misc/404"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails seems to be ignoring authenticity tokens for AJAX requests. For instance, I purposely
My rails server seems to break after installing the facebooker plugin. Any suggestions on
it seems that on Rails or erb, the only way to output anything is
This seems to have been asked before: rails decimal precision and scale But when
So I have a Rails app (which in this case seems like it would
I am building a Rails app, and it seems that common practice is to
is it true that Rails depend on cookies? It seems that flash is a
Or is Rails by itself just good for developing APIs? It seems that ASP.NET
I was reading Simply Rails by Patrick Lenz... maybe I missed something, it seems
I have a class User in Rails using Mongoid and Devise. I can't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.