Monday, November 21, 2011

rescue_from temporary fix for rails 3.0 and 3.1

In rails 3.0 and 3.1 rescue_from will not successfully rescue a ActionController::RoutingError (Bug Report). Based on comments in the bug report here is the solution I came up with. A way that handles this bug temporarily and once it is fixed all that needs to be cleaned up is a single line in the routes.

First set up a simple errors controller:
class ErrorsController < ApplicationController
  def missing_page
   render :status => :not_found
  end
end

The view for missing_page is intended to be shown to visitors as the 404 page, it uses the application layout as set up here but you can set :layout to false or whatever other layout you might wish to use.
In the application controller add the following lines:
rescue_from ActiveRecord::RecordNotFound, :with => :missing_page
rescue_from ActionController::UnknownAction, :with => :missing_page
rescue_from ActionController::RoutingError, :with => :missing_page
The first two lines work as expected, the line with ActionController::RoutingError does not work correctly though, it will start working once the bug is fixed.

The temporary fix for routing errors not being handled properly is to add the following line as the last route in the route file.
match '*path', :to => 'errors#missing_page'

Once the bug is fixed all you need to do to clean this up is remove the line that was placed at the end of the route file.

17 comments:


  1. Thank you for sharing like this information. This is the most easy way of learning. This helps me to get some idea regarding this and helps me to bring a creative thought.
    Java Training in Chennai

    ReplyDelete
  2. Brilliant post thanks for lots of sharing really great post i am very happy to read your post e commerce web development

    ReplyDelete
  3. I am very much fond of your nice post..IICT is the best Java Training Institute in Chennai managed by MNC Experts.

    ReplyDelete
  4. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,
    PMP Training | PMP Training in Chennai

    ReplyDelete
  5. Thanks for sharing this informative blog. I have read your blog and I gathered some valuable information from this blog. Keep posting.
    Regards,
    Java Training in Chennai | SAP Training in Chennai

    ReplyDelete
  6. Good one, very informative.. thanks for sharing your views and ideas.. it is very useful to me.. thanks once again.

    Best Java Training in chennai

    Java Course in chennai

    ReplyDelete
  7. I am perusing your post from the earliest starting point, it was so fascinating to peruse and I feel because of you for posting such a decent blog.
    Education | Article Submission sites | Technology

    ReplyDelete
  8. Thank you so much for all the wonderful information about sensors! I love your work
    PHP Training in Chennai |
    PHP Course in Chennai |
    PHP Training Institute in Chennai

    ReplyDelete
  9. Wow, what great information. I am sure the info on your blog will help others, as I am trying to do as well.
    German Language Classes in Chenna |
    German Classes in Chennnai |
    German Courses in Chennai

    ReplyDelete
  10. Nice blog thanks for sharing Out of creative ways to set up a vegetable garden? Karuna Nursery is run by the best gardeners in chennai who are ready to offer you with amazing
    plant nursery in chennai

    ReplyDelete
  11. Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.

    ReplyDelete