Would "rails generate config" be a useful feature?

67 views
Skip to first unread message

Kyle Rippey

unread,
May 5, 2015, 2:00:14 PM5/5/15
to rubyonra...@googlegroups.com
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?

Kyle Rippey

unread,
May 5, 2015, 2:03:23 PM5/5/15
to rubyonra...@googlegroups.com
Oops, I meant "rails generate config facebook app_id app_secret". Obviously this belongs with all of the other generators.

Justin Weiss

unread,
May 5, 2015, 10:33:18 PM5/5/15
to rubyonra...@googlegroups.com
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.

Kyle Rippey

unread,
May 6, 2015, 1:51:29 AM5/6/15
to rubyonra...@googlegroups.com
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"] %>

Codrut Gusoi

unread,
May 7, 2015, 2:37:59 AM5/7/15
to rubyonra...@googlegroups.com
How about somewhere in the middle, default blank and a flag for people who want the ENV vars to be added automatically?

richard schneeman

unread,
May 7, 2015, 10:28:21 AM5/7/15
to rubyonra...@googlegroups.com, rubyonra...@googlegroups.com
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.

---
Richard Schneeman



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages