How do I set environment variables in my Rails application?
<p>I’m using Rails 4.2.3 and trying to create environment variables accessible only in my application (as opposed to storing them in a ~/.bashrc file or some OS-specific solution).  So I created the file “config/environment_variables.yml” with</p>

<pre><code>development:
  GOOGLE_CLIENT_ID: 999995268318-o5ejue1pgtsjoid0f0k8r7lcksfse6hk.apps.googleusercontent.com
  GOOGLE_SECRET: 28bfoTU_RbRKkdxv7_wkNzw5
  FACEBOOK_KEY: 1588888667329742
  FACEBOOK_SECRET: 4444g1faeb11111e5392892d397b79f8e
production:
  GOOGLE_CLIENT_ID: 999995268318-o5ejue1pgtsjoid0f0k8r7lcksfse6hk.apps.googleusercontent.com
  GOOGLE_SECRET: 28bfoTU_RbRKkdxv7_wkNzw5
  FACEBOOK_KEY: 1588888667329742
  FACEBOOK_SECRET: 4444g1faeb11111e5392892d397b79f8e
</code></pre>

<p>and then I created the file “config/initializers/environment_variables.rb”</p>

<pre><code>module EnvironmentVariablesExample
  class Application &lt; Rails::Application
    config.before_configuration do
      env_file = Rails.root.join("config", 'environment_variables.yml').to_s

      if File.exists?(env_file)
        YAML.load_file(env_file)[Rails.env].each do |key, value|
          ENV[key.to_s] = value
        end # end YAML.load_file
      end # end if File.exists?
    end # end config.before_configuration
  end # end class
end # end module
</code></pre>

<p>but when I startup my server on my local machine with “rails s,” I get this error</p>

<pre><code>Exiting
/Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:8:in `[]=': no implicit conversion of Fixnum into String (TypeError)
    from /Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:8:in `block (2 levels) in &lt;class:Application&gt;'
    from /Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:7:in `each'
    from /Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:7:in `block in &lt;class:Application&gt;'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:27:in `each'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/railtie/configuration.rb:53:in `before_configuration'
    from /Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:3:in `&lt;class:Application&gt;'
    from /Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:2:in `&lt;module:EnvironmentVariablesExample&gt;'
    from /Users/davea/Documents/workspace/pushupmoose/config/initializers/environment_variables.rb:1:in `&lt;top (required)&gt;'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:652:in `block in load_config_initializer'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:651:in `load_config_initializer'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:616:in `block (2 levels) in &lt;class:Engine&gt;'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `each'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `block in &lt;class:Engine&gt;'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
    …
</code></pre>

<p>What am I doing wrong in my environment set up above?  Thanks, - Dave</p>