Very Noob Question: index.html

Hi,

I have a very noob question. I just started on RoR this week, glad to be
on board. I’m just wondering where I edit the first page when people
come to the site, index.html. There seems to be one in the public
folder. However, how do I make that a dynamic page?

Thanks

Rename or remove that file and add a default route.

Look in your routes.rb file. You’ll see something like this…

You can have the root of your site routed by hooking up ‘’

– just remember to delete public/index.html.

map.connect ‘’, :controller => “index”

Uncomment that and generate an index controller or whatever name you
like.


James M.

Hi –

On Wed, 6 Jun 2007, Newby wrote:

Hi,

I have a very noob question. I just started on RoR this week, glad to be
on board.

Welcome!

I’m just wondering where I edit the first page when people
come to the site, index.html. There seems to be one in the public
folder. However, how do I make that a dynamic page?

Rails uses its routing system to figure out what to do given a
particular URL. That applies even when the URL is empty: you have to
register a routing rule that says what to do in response to the empty
URL.

To do this, look inside the file config/routes.rb. You’ll see a
section like this:

You can have the root of your site routed by hooking up ‘’

– just remember to delete public/index.html.

map.connect ‘’, :controller => “welcome”

You want to uncomment the third line, and customize it to correspond
to whatever controller/action combo you want triggered by the empty
URL. (The action defaults to “index”, so the example above triggers
the index action of the welcome controller.)

So a typical case might look like:

map.connect ‘’, :controller => “main”, :action => “top”

or

map.connect ‘’, :controller => “main” # default to “index” action

etc.

And, like it says, don’t forget to delete public/index.html :slight_smile:

David


Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (Ruby for Rails)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

The index.html that is in public is just a place holder. Delete that
file and add a route in routes.rb for the “/” path to point to a
controller and action you want for the default content.

I recommend getting “Agile Web D. with Rails” which starts
with a short and to the point tutorial that gets an application up and
running, then dives into more detail on each component of an
application.

Michael