1

I'm trying to run my rails in development mode but I'm greeted by this:

Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`

I did a rake secret and added it to my secrets.yml

production:
  secret_key_base: 9c9fc2f9a0a212bb2bc5be64ec3bb722fc5ae01d79c1ed181f1b3a8e858c25f076e7845b67f75ab658947557d81c7fc08ba5bddf20860ec5d681b701be05***

Which results in this message in the browser.

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

So how do I correctly add a secret to my secrets.yml ?

Update

I've created a new secret using rake secret. Then added it to export SECRET_KEY_BASE= and ran it. Now when I do echo $SECRET_KEY_BASE I get the secret I just added. When I visit my localhost I get the We're sorry, but something went wrong. If you are the application owner check the logs for more information. message.

This is my secrets.yml

development:
  secret_key_base: 89dacb16fd905ff4c6352ac93f4676a5dd6e***93edce9a5be796712d54b57b91e1335598fd73e3998fddbbdeaf3ee7f65157f2fb01ce1bea5658aa7bf745d1f

test:
  secret_key_base: cf351585b2cb43459f5a073cbfd885b3dd2af44124f13a85552***78c1cf06625c121cd3b7857f86e7fe2ba11180066753142143231c79c513e71e20372a0462

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Update 2

This is shown in my Rails log when I visit the localhost:

I, [2014-11-02T16:24:57.655671 #13782]  INFO -- : Started GET "/" for 127.0.0.1 at 2014-11-02 16:24:57 +0100
I, [2014-11-02T16:24:57.670779 #13782]  INFO -- : Processing by MoviesController#index as HTML
I, [2014-11-02T16:24:57.694266 #13782]  INFO -- : Completed 500 Internal Server Error in 23ms
F, [2014-11-02T16:24:57.697056 #13782] FATAL -- : 
ActiveRecord::StatementInvalid (Could not find table 'users'):
  app/controllers/application_controller.rb:18:in `current_user'
  app/helpers/sessions_helper.rb:26:in `logged_in?'
  app/controllers/movies_controller.rb:5:in `index'

Hm, I think I need to create my database in production.

Running RAILS_ENV=production rake db:create db:schema:load now lets me visit my website, allthough there's no styling etc.

This topic adresses the problem of the no styling. I can now visit and use my App in development on my localhost. Now see if the deployed version works a bit better.

Community
  • 1
  • 1
Peter Boomsma
  • 8,851
  • 16
  • 93
  • 185
  • Is this an upgraded or fresh initialization of rails 4 project? – vee Nov 02 '14 at 14:31
  • It's a fresh 4.1 project. If found `rhc set-env SECRET_KEY_BASE=key`. I've just installed the RHC gem and made a account (which is needed to run the command). I wonder if this would do anything... – Peter Boomsma Nov 02 '14 at 14:34
  • If you have an environment variable, you could reference that in your `config/secrets.yml`. See linked: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml – vee Nov 02 '14 at 14:42
  • How do I see if I have an `environment variable`? – Peter Boomsma Nov 02 '14 at 14:54
  • On your terminal prompt, run `echo $SECRET_KEY_BASE`, that should show you the value if it's set. – vee Nov 02 '14 at 14:55
  • Running `echo $SECRET_KEY_BASE` doesn't show me anything. So the problem is that my secrets.yml is looking for a variable called `$secret_key_base`. But that doesn't excist. So I have to add on to my `environment variable` ? – Peter Boomsma Nov 02 '14 at 15:03
  • I thought you already had the environment variable. You can test that using `export SECRET_KEY_BASE=`. Replace `` with your key. Try this first and could you also post your full `secrets.yml` as is, please update your question to add this. – vee Nov 02 '14 at 15:11
  • Thanks for the help. I'll create an answer using the information. – Peter Boomsma Nov 02 '14 at 15:43
  • Like must be renamed to secrets.yml.erb – Dmitry Polushkin Oct 25 '15 at 13:20

0 Answers0