views:

202

answers:

1

I have a root path in my routes file: map.root :controller => 'games', :action => 'index'

The problem is that if anyone goes to: http://domain.com/games it doesn't show the root, thus we're creating two urls for the same page.

Is there a way to change any hit to http://domain.com/games to http://domain.com ?

I'd rather not fiddle around with a before_filter in the application controller if there's a nice way to do it in the routes folder.

Thanks!

+2  A: 

The easiest way is to just set up a redirect.

map.redirect('/games','/')

Although, your problem is really that the /games route shouldn't be there in in the first place.

Remove the catchall route at the bottom of your routes.rb file, and this won't even be a problem.

Jamie Wong
What Jamie suggested about removing the route from routes.rb. Then just avoid having any of your code link to the `/games` route, you can use the `root_path` helper method.
Karl
Hi guys, so I have:map.resources :gamesmap.root, :controller => 'games', :action => 'indexThe thing is, I need show, create, new, destroy for games, but the index should always be the root path. I tried the redirect, but I get this error:No route matches "/"Is there a way to map.resources :games, but not the index?
kineticac
kineticac