Create Custom Root

Used to setup a custom root to: with controller
Icons/chart bar
Used 48 times
Created by
R Richard Wise

This template assumes you don't already have a root defined in config/routes.rb

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION=""
Template Source

Review the code before running this template on your machine.

# ask for root controller name
controller_name = ask('what do you want to name your controller? (example: Pages)')
# ask for root page name
page_name = ask('what do you want to name your page? (example: home)')

#generate controller
generate(:controller, controller_name, page_name) if yes?("Generate controller?")

# make controller#page_name root path 
inject_into_file 'config/routes.rb', "  root to: '#{controller_name}##{page_name}'\n", :before => /^end/
Nilesh Ajwelkar

This generates the following in the routes. 
# root to: 'Pages#home'

This results in error. This should have controller name in small case.
# root to: 'pages#home'