Quick routes question

I have

This is a catch-all for routes that don’t exist, visitor is

redirected to home page.
ActionController::Routing::Routes.draw do |map|
map.connect ‘:controller/:action/:id’
map.connect ‘*path’, :controller => ‘home’
end

in my routes.rb file.
This works fine to redirect to the home page if somebody types a wrong
or missing address into the web browser.
But it doesn’t change the url/uri displayed in the browser.

How can I change the url/uri to display what it should be? (in this
case, domain followed by /home)

Nevermind, I’ve found a simple solution that works:
I’ve simply made the catch-all route controller/action go to a
controller where I def’d an action method that creates a flash message
and redirects to the home page.

In routes.rb:

This is a catch-all for routes that don’t exist, visitor is

redirected to home page.
ActionController::Routing::Routes.draw do |map|
map.connect ‘:controller/:action/:id’
map.connect ‘*path’, :controller => ‘home’, :action =>
‘catcher’#:controller => ‘home’, :action => ‘index’
end

In the corresponding controller:

def catcher
flash[:notice] = ‘Seems that the page you were looking for does
not exist, so you’ve been redirected here.’
redirect_to :action => ‘index’
end

It’s not the most sophisticated thing but it works.
Does anybody know the param to include in my flash message to display
the originally requested address?

On Aug 23, 2007, at 6:39 PM, [email protected] wrote:

map.connect '*path', :controller => 'home'

You could route this to a “redirect_home” action that calls
redirect_to /home

Ah, Thanks Mr. Ivey, but it looks like my watery brain kicked in just
minutes before your post! I already came to that conclusion.
That said, I can see where adding loggin for this catcher method could
generate useful SEO data for site features or simply routes that
should be added! Of course it is also a good way to catch malicious
visitors that should be banned in the htaccess file.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs