Rails: display user friendly routing error message in rails

I am working in rails 2.3 on mac osx leopard. every time i type in a url that doesn't exist in rails app i get the following error:

Routing Error

No route matches "/whatever_i_typed" with {:method=>:get}

      

this is a development search, but I was wondering how I can make sure users see a friendlier 'oops! not found. "I was thinking about starting a rescue block ... but I didn't know where to put it, and I don't know the error code (like ActiveRecord :: RecordNotFound)

thank! Yuval

+1


source to share


3 answers


This error will never appear during production. Instead, users will see the public / 404.html page.

To try this on your localhost put passenger / mongrel in production mode. Override the method local_request?

on yours ApplicationController

like so:



class ApplicationController
  def local_request?
    false
  end
end

      

If you want to experiment with dynamic behavior, you can check out the class method rescue_from

on ActionController.

+2


source


What about

map.connect '*url', :controller => "not_found"

      



how is the last entry routes.rb

? I think this should do the trick, right?

0


source


0


source







All Articles