Ruby on Rails Routing Root route

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

You can add a home page route to your app with the root method.

# config/routes.rb
Rails.application.routes.draw do
  root "application#index"
  # equivalent to:
  # get "/", "application#index"  
end

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  def index
    render "homepage"
  end
end

And in terminal, rake routes (rails routes in Rails 5) will produce:

root     GET    /         application#index

Because the homepage is usually the most important route, and routes are prioritized in the order they appear, the root route should usually be the first in your routes file.



Got any Ruby on Rails Question?