When a request asking for an action in a controller that does not exist in your application a not found error page is displayed. You can actually use routes to redirect this requests to the a default page.

Just add the following line the last rule in your config/routes.rb file:

map.connect ‘*path’, :controller => ‘main’, :action => ‘redirect_to_default’

Whenever a request asking for an action in a controller that you have not defined hits your application, rails will call the action ‘redirect_to_default’ in the ‘main’ controller (you can obviously change the controller and the action to fit your needs).

The code for the redirect_to_default action is a simple rails redirect:

def redirect_to_default
  redirect_to :action => 'index'
end

Leave a Reply