O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting a Default Page

Before moving on to more “serious” concerns about developing applications, there’s one question that web developers always seem to ask about 15 minutes into their first Rails experience:

How do I set a default page for the application?

The Rails welcome page, shown in Figure 1-2, is just plain ugly. There are two ways to change that:

  • Edit the public/index.html file and put in something more to your liking

  • Delete the public/index.html file and tweak the config/routes.rb file

The first one is pretty easy, but it doesn’t integrate very tightly with your Rails application. The second approach lets you pick a controller that will run if the Rails application is run without specifying a controller—that is, in the test environment, by directly visiting http://localhost:3000/.

To make this work, you’ll need to enter an extra line in the config/routes.rb file. Near the bottom of that, you’ll see:

# You can have the root of your site routed with map.root --
# just remember to delete public/index.html.
# map.root :controller => "welcome"

Change the last line of that to:

map.root  :controller => "hello", :action => "index"

Save the file, make sure you’ve deleted or renamed the public/index.html file, and restart your server. You should see something like Figure 3-6.

Accessing a controller by default, when the URL doesn’t specify one

Figure 3-6. Accessing a controller by default, when the URL doesn’t specify one

Don’t worry if this edit seems mysterious. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required