2

I'm trying to deploy my app with mina. When it starts to run migrations I got this error:

-----> Migrating database
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:

  config.secret_key = 'key here.......'

Please ensure you restarted your application after installing Devise or setting the key.
.........

In my devise initializer I have config.secret_key = ENV["SECRET_KEY_BASE"]

How to add this key to my app? Are secret_key_base and secret_key different?

This might be stupid but I dont know how to add this key.

Locally everything works fine

ps I'm using figaro

kirqe
  • 2,431
  • 4
  • 37
  • 63

2 Answers2

1

open your rails app folder go to

config/initializers/devise.rb

and paste this line of code at the end:

config.secret_key = *****

where ***** is the string your console gives you when the error pops out.

as an Environment variable:

If you want an enviorment Variable you can go different ways, for example replace the above line of code to this:

config.secret_key = ENV['DEVISE_SECRET_KEY']

then you can create a the variable on a keys.yml file and add it to your ./gitignore file.

after that you can import the yaml file to your app like this:

config/application.rb:

   ENV.update YAML.load(File.read(File.expand_path('../keys.yml', __FILE__)))
   module yourApp
     ...
     ...
   end
Rodrigo Zurek
  • 4,555
  • 7
  • 33
  • 45
  • Is it ok to expose this code? It'll be visible on git. This is what I'm worried about. – kirqe Jan 14 '15 at 20:53
  • If you are storing on git I would use an environment variable to store the key. ex: `ENV['DEVISE_SECRET_KEY']` – Jordan Jan 14 '15 at 20:55
  • I store it in env var but when I deploy with mina it cant see this key. – kirqe Jan 14 '15 at 20:56
  • 1
    sorry I somehow missed that part in your OP. In terminal just type `echo "export SECRET_KEY_BASE="insert key here" >> .bashrc` – Jordan Jan 14 '15 at 21:00
1

I added

set :shared_paths, ['config/database.yml', 'log', 'config/secrets.yml']

to my deploy.rb and it solved my problem.

In the secrets.yml I set DEVISE_SECRET

kirqe
  • 2,431
  • 4
  • 37
  • 63