pitosalas
pitosalas

Reputation: 10902

Where is the root route in Rails 6?

It used to be that routes.rb had a root route line. But I don't see it anymore even though when I run the server I see the "Yay! You’re on Rails!" page. I can't find where it is defined so I can override it!

Upvotes: 3

Views: 2910

Answers (3)

pitosalas
pitosalas

Reputation: 10902

Above answers are correct but incomplete.

With Rails 6 it seems that there's no explicit root route ('/'). Instead the rails gem(s) handle it by displaying the standard "Yay you're on Rails" page (see railsties/templates/welcome/index.html.erb). It's a fixed page, bypassing routes.rb and layouts etc.

This behavior seems to only happen in development mode and when you haven't actually defined a root route.

So it seems that the page is fixed and unmodifiable. But it can easily be replaced by a root route.

Upvotes: 2

Steven Foster
Steven Foster

Reputation: 216

The routes.rb file is in the config/ directory of your rails project. You can define a root route there and direct it using the routes DSL

Upvotes: 2

arieljuod
arieljuod

Reputation: 15838

On a new project it doesn't use a root route, it just renders the rails' default new project page.

Just add the line:

root to: 'somecontroller#someaction'

and you are done.

Upvotes: 5

Related Questions