Would "rails generate config" be a useful feature?

I was considering creating a pull request to add this functionality, but just wanted to get some thoughts on the idea first.

Basically, since Rails 4 added the handy config_for() functionality to support loading custom yml files from the config directory, I thought it would be nice if we had a generator to compliment it.

Here’s an example:

“rails config facebook app_id app_secret” will create config/facebook.yml (if it doesn’t already exist) with the keys stubbed out for each environment:

development:
app_id: <%= ENV[“FACEBOOK_APP_ID”] %>
app_secret: <%= ENV[“FACEBOOK_APP_SECRET”] %>

test:
app_id: <%= ENV[“FACEBOOK_APP_ID”] %>
app_secret: <%= ENV[“FACEBOOK_APP_SECRET”] %>

Do not keep production secrets in the repository,

instead read values from the environment.

production:
app_id: <%= ENV[“FACEBOOK_APP_ID”] %>
app_secret: <%= ENV[“FACEBOOK_APP_SECRET”] %>

``

I think this could be handy, but also help reinforce the idea that secret values should not be stored in a repository.

Thoughts?

Oops, I meant “rails generate config facebook app_id app_secret”. Obviously this belongs with all of the other generators.

I like the idea, but I’m not sure about ENV-as-default in dev and test environments. You usually won’t have the environment variable set before you generate the config, so it’s no different than having it start off blank. And either someone will have to set the environment variable, or tweak the config before their app will run properly. I don’t know which would make a better default.

I agree, I debated a lot between leaving them blank for non-production environments versus using ENV variables. I do see how ENV variables as default could be more confusing, especially to newer Rails devs, as it’s not a pattern that we see anywhere else in Rails. Ultimately, I don’t have a strong preference either way and I’d love to hear if other people have opinions one way or the other.

Newly proposed behavior for “rails generate config facebook app_id app_secret”:

development:
app_id:
app_secret:

test:
app_id:
app_secret:

Do not keep production secrets in the repository,

instead read values from the environment.

production:
app_id: <%= ENV[“FACEBOOK_APP_ID”] %>
app_secret: <%= ENV[“FACEBOOK_APP_SECRET”] %>

``

How about somewhere in the middle, default blank and a flag for people who want the ENV vars to be added automatically?

I’m :-1: on all file based YML config. :+1: on env based config.

Either way, I would suggest writing it up as a gem to get some real world feedback.