Generator for root action

I was watching DHH's demo on ActionCable and something took my attention more than it should in my opinion.

One of the first things we do for every application is to generate a root action and then manually edit routes.rb:

1 - rails g controller welcome index
2 - change routes.rb from "get 'welcome/index'" to "root to: 'welcome#index'"

Maybe it would be a good idea to introduce some kind of flag in the generator to get this done automatically. It may be a tiny change but it makes a difference when you are demoing any Rails application from scratch.

Maybe something like:

rails g controller welcome index:root help

Which would generate some routes like:

root to: 'welcome#index'
get 'welcome/help'

If another root action already exists or if two actions are flagged as root actions the generator command would raise an error.

Is this something you have considered before?


Hi Rodrigo,

I don’t think this is a common enough case that we need to have it in the generator. You’re mostly only going to set the root once. Editing this by hand is imo just fine.

Hi DHH, okay, thanks for considering. I understand, the common use case I can see is for demonstration purposes mostly, when you are building a Rails application from scratch and using some demonstration time to edit the root route seems a bit distracting, but I agree, this isn't a very compelling case to introduce such a change.