views:

87

answers:

3

I see lots of :

map.root :controller => "home"

Its I know simple, but what does home point to? A file? A controller? How/where does it gets its magic?

A: 

In that case, Rails would route root requests to the 'home' controller, although you should probably specify an action just to be unambiguous... I imagine you do want the index action

Gareth
Does one define a "home" controller - like "home_controller"? Is that what it means? I was wondering if it defaulted to something I was not aware of.
rtfminc
Yes, you'll then have a home_controller.rb right alongside your other controllers. You make this controller the same way you'd make any other one.
LanceH
Thanks, I'd seen many tutorials etc that had the text "map.root :controller => “home”" without explaining this that I wondered if it had some other behind-the-scene magic I was not aware of.
rtfminc
+2  A: 

Read the documentation.

This particular route maps "/" to the action index (default) of the controller "home", most likely in "app/controllers/home_controller.rb".

map.connect "foo", :controller => "something", similarly, maps /foo to the index action of the "something" controller.

August Lilleaas
A: 

Hi rtfminc

map.root :controller => "home" has two things hapenning

1 - map.root will always consider as your web sites home page

as an example if you have your home page in a controller called 'website' and in an action called 'home_page'

you can give the root as

map.root :controller => "website", :action => 'home_page'

2 - If you are directing to a controller with out giving an action, rails will default redirect to that controllers 'index' action

So in this case

map.root :controller => "home" will redirect to 'home' controllers 'index' action

hope this helps

cheers, sameera

sameera207
Yes, thanks for the explanation. Sometimes I need things spelled out for me in detail.
rtfminc
Also remember to delete the default index.html file from the public folder. If not that route just wont work at all. :)
Shripad K