views:

1472

answers:

6

I am trying to get the root of my application to route to a default controller. From what I read, this should be possible with something like this at the bottom of my routes.rb file:

map.root :controller => 'albums'

or perhaps even:

map.home  '', :controller => 'albums'

However, when I try navigating to http://myhost:8000/, I just see the rails welcome page. I am restarting the application with the following command after making the change to routes.rb and before testing it:

sudo mongrel_cluster_ctl restart

Here is some more possibly pertinent environment information:

% rails -v
Rails 2.3.3

% ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

I am sure I'm missing something simple, but I can't see what it is. Any ideas?

+3  A: 
map.root :controller => 'albums'

Is the correct syntax.

A few things to try:

  • delete index.html from public.
  • Look at the output of "rake routes", do you see something along the lines of:
root   /  {:controller=>"albums", :action=>"index"}
  • Are you 100% sure the right cluster is being restarted: try running script/server and navigating to root on port 3000
Sam Saffron
+1  A: 

Routes at the end of routes.rb are the last to get used, therefore you may want to try with 'map.root...' at the top of your routes.rb

Ryan Neufeld
+3  A: 

Have you deleted the static public/index.html page that Rails creates? If this is still in your app it will be shown instead of the root page you defined in the routes.

Eifion
+11  A: 

Delete the public/index.html file.

JimNeath
Thanks, I knew it had to be something simple!
pkaeding
A: 

I was scratching my head for a while now. Deleting public/index.html file did the glitch for me. Thanks!

A: 

Hi

I have a slightly different problem. I've set up a map.root entry and it works with mongrel. However when I use apache2 as the web server with Passenger module I get a '500' error. If I re-instate my /public/index.html then it works under apache2.

I have tried to go directly as:

http:///home/index

This also gives me the same '500' error.

Please can somebody tell me what I'm doing wrong?

Hi

I found someone else who had had the same problem. Turns out that Passenger is running in production mode whilst my app was in development mode.

I put Passenger into development mode by adding the following line to my Virtual Hosts file

RailsEnv = development

Restarted Apache and it all works!!

Phew!

Purvez

Purvez
If you have a new issue, please post it as a new question. You can ask a new question by clicking the "Ask Question button in the top-right corner of the page. Also, if you find an answer to a question (even if it is your own question, you can then post it as an answer, rather than editing your original question.
pkaeding