views:

259

answers:

2

hello, i am working in rails 2.3 on mac osx leopard. every time i type a url that does not exist in a rails application i get the following error

Routing Error

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

this is find for development, but i was wondering how i can make sure users see a friendlier 'oops! not found' page. i was thinking about doing a begin...rescue block but i didn't know where to put it, not did i know the error code (i.e ActiveRecord::RecordNotFound)

thanks! yuval

A: 

How about

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

as a last routes.rb entry? I think it should do the trick, shouldn't it?

alamar
is there no way to 'rescue' the error like you would if you had an ActiveRecord error?
yuval
There's no error! It's just routing happens.
alamar
+2  A: 

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

To try this out on your localhost, put passenger/mongrel into production mode. Override the local_request? method on your ApplicationController like so:

class ApplicationController
  def local_request?
    false
  end
end

If you'd like to experiment with dynamic behavior you can check out the rescue_from class method on ActionController.

austinfromboston
thank you for your response, it's helpful
yuval