title: Missing secret_key_base in rails production
body: <p>I don't understand why my secret_key_base is not found. When I start my app in production I get this message on web browser : <code>Missing 'secret_key_base' for 'production' environment, set this value in 'config/secrets.yml'</code></p>
  
  <p>My <code>config/secret.yml</code> looks like this :</p>
  
  <pre><code>production:
    secret_key_base: &lt;%= ENV["SECRET_KEY_BASE"] %&gt;
  </code></pre>
  
  <p>When I replace <code>&lt;%= ENV["SECRET_KEY_BASE"] %&gt;</code> with the key generated it works, otherwise, it is not recommended...</p>
  
  <p>So I put my key in <code>/etc/profile</code> &amp; <code>~/.bashrc</code> &amp; <code>~/.rvm/environment/ruby-2.1.5</code> as follow :</p>
  
  <pre><code>export SECRET_KEY_BASE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  </code></pre>
  
  <p>When I start a rails console in production mode I can see my key :</p>
  
  <pre><code>rails c production
  Loading production environment (Rails 4.1.6)
  2.1.5 :001 &gt; ENV["SECRET_KEY_BASE"]
   =&gt; "XXXXXXXXXXXXXXXXXXXXX"
  </code></pre>
  
  <p>I don't get why it is not working knowing all of that. Am I missing something obvious ?</p>
  
  <hr>
  
  <p>Complete error log :</p>
  
  <pre><code>ERROR RuntimeError: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb:462:in `validate_secret_key_config!'
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb:195:in `env_config'
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/engine.rb:510:in `call'
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
          /home/xxx/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
          /home/xxx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
          /home/xxx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
          /home/xxx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 1 :</strong></p>
  
  <p>I took a look at <code>~/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb</code> and I did some debug trace using <code>puts</code>. It looks like my ENV variable is <code>nil</code> for Ruby in this file but also in <code>config/secret.yml</code> when the file is parsed.</p>
  
  <p>Here are the log I put on the file during the parsing process :</p>
  
  <pre><code>secrets = ActiveSupport::OrderedOptions.new
  yaml = config.paths["config/secrets"].first
  if File.exist?(yaml)
    puts "FILE EXIST !"
    puts ENV["SECRET_KEY_BASE"]
    require "erb"
    all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {}
    puts all_secrets.inspect
    env_secrets = all_secrets[Rails.env]
    puts env_secrets.inspect
    secrets.merge!(env_secrets.symbolize_keys) if env_secrets
    puts secrets.inspect
  end
  </code></pre>
  
  <p>And here is the result when I start my server using rvmsudo rails s -e "production" -p 80</p>
  
  <pre><code>FILE EXIST !
                  &lt;-------------- (nil)
  {"development"=&gt;{"secret_key_base"=&gt;"OK"}, "test"=&gt;{"secret_key_base"=&gt;"OK"}, "production"=&gt;{"secret_key_base"=&gt;nil}}
  {"secret_key_base"=&gt;nil}
  {:secret_key_base=&gt;nil}
  </code></pre>
  
  <p>It looks like rvmsudo doesn't pass env variable, I will take a look at it...</p>