Used to setup a custom root to: with controller
Used 51 times
R
Richard Wise
Usage
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="https://railsbytes.com/script/xYasyx"
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/
Comments
Nilesh Ajwelkar
Hi,
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'
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'