Blog / How to add a Root Route to your Rails app

How to add a Root Route to your Rails app

Blair Rorani

February 23, 2021

You need to replace the default, “Yay! You’re on Rails” landing page with a real index page for your app.

Create a route 🛤️

  1. Go to config > routes.rb file
  2. In the Rails.application.routes.draw method, enter the route: get root, to: "main#index"


Create a controller 👨‍✈️

  1. Go to app > controllers folder
  2. Create a file named main_controller.rb
  3. Create a class named MainController and inherit from ApplicationController
  4. Define a method named index.


Create a view 🏞️

  1. Go to app > views folder
  2. Create a folder named main
  3. In that folder create a file named index.html.erb
  4. Add HTML

app > views > main > index.html.erb

View new page 👀

  1. Go to http://localhost:3000
  2. You’ll see the new page


P.S. You might enjoy following me on Twitter.


Want to stay up-to-date with Ruby on Rails?

Join 52,887+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.