Variables ENV Variables

I recently asked a similar question, but since the problem has changed somewhat, I decided to create a new question - I hope this is the expected approach?

By pushing my Rails 4 application to Heroku, I keep getting the page with the internal server error, and the error:

You must set config.secret_key_base to your application configuration

This is because my .gitignore file contains config / initializers / secret_token.rb intentionally.

I set the Figaro gem so that I can set my secret_key_base as an environment variable for added security. I checked Heroku that the key was installed correctly.

My code for secret_token.rb is as follows:

MyApp::Application.config.secret_key_base = ENV["SECRET_KEY_BASE"] 

However, I still get the same problem.

Can anyone help?

+4
source share
3 answers

I did something similar to you that worked, but did not use Figaro. I founded it this blog post

In short, here is what I did:

1) remove config / initializers / secret_token.rb from your .gitignore

2) Use this code for your secret_token.rb:

 MyApp::Application.config.secret_token = if Rails.env.development? or Rails.env.test? ('x' * 30) # meets minimum requirement of 30 chars long else ENV['SECRET_TOKEN'] end 

3) commit and re-click

4) set Heroku env variale as:

 heroku config:set SECRET_TOKEN=12345..... 

It works as soon as Heroku restarts after configuring.

+9
source

You can set environment variables on the hero: https://devcenter.heroku.com/articles/config-vars

You need to set the SECRET_KEY_BASE environment variable for the hero using this command:

 heroku config:set SECRET_KEY_BASE=value 
+4
source

This can help people using Rails + 4.1:

"When deploying a Rails 4.1+ application, Heroku will point SECRET_KEY_BASE to your default application." ( Https://blog.heroku.com/container_ready_rails_5 )

In other words, you do not have to do anything. You can omit secrets.yml (the standard version that is) from your .gitignore file without fear of losing production secrets.

0
source

Source: https://habr.com/ru/post/1500009/


All Articles