ruby - How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1) -


i've created rails app (rails 4.1) scratch , facing strange problem not able solve.

every time try deploy app on heroku error 500:

missing secret_key_base 'production' environment, set value in config/secrets.yml

the secret.yml file contains following configuration:

secret_key_base: <%= env["secret_key_base"] %> 

on heroku have configured environment variable "secret_key_base" result of "rake secret" command. if launch "heroku config", can see variable correct name , value.

why still getting error?

thanks lot

i had same problem , solved creating environment variable loaded every time logged in production server , made mini guide of steps configure it:

https://gist.github.com/pablosalgadom/4d75f30517edc6230a67

i using rails 4.1 unicorn v4.8.2, when tried deploy app didn't start , in unicorn.log file found error message:

app error: missing `secret_key_base` 'production' environment, set value in `config/secrets.yml` (runtimeerror)

after research found out rails 4.1 changed way manage secret_key, if read secrets.yml file located @ examplerailsproject/config/secrets.yml you'll find this:

# not keep production secrets in repository, # instead read values environment. production:   secret_key_base: <%= env["secret_key_base"] %> 

this means rails recommends use environment variable secret_key_base in production server, in order solve error should follow steps create environment variable linux (in case ubuntu) in production server:

  1. in terminal of production server execute next command:

    $ rails_env=production rake secret 

    this returns large string letters , numbers, copy (we refer code generated_code).

  2. login server

    • if login root user, find file , edit it:

      $ vi /etc/profile 

      go bottom of file ("shift + g" capital g in vi)

      write environment variable generated_code (press "i" key write in vi), sure in new line @ end of file:

      $ export secret_key_base=generated_code 

      save changes , close file (we push "esc" key , write ":x" , "enter" key save , exit in vi).

    • but if login normal user, lets call "example_user" gist, need find 1 of other files:

      $ vi ~/.bash_profile $ vi ~/.bash_login $ vi ~/.profile 

      these files in order of importance, means if have first file, wouldn't need write in others. if found 2 files in directory ~/.bash_profile , ~/.profile have write in first 1 ~/.bash_profile, because linux read 1 , other ignored.

      then go bottom of file ("shift + g" capital g in vi).

      and write our environment variable our generated_code (press "i" key write in vi), sure in new line @ end of file:

      $ export secret_key_base=generated_code 

      having written code, save changes , close file (we push "esc" key , write ":x" , "enter" key save , exit in vi).

  3. you can verify our environment variable set in linux command:

    $ printenv | grep secret_key_base 

    or with:

    $ echo $secret_key_base 

    when execute command, if went ok, show generated_code before. configuration done should able deploy without problems rails app unicorn or other.

when close shell terminal , login again production server have environment variable set , ready use it.

and thats it!! hope mini guide solve error.

disclaimer: i'm not linux or rails guru, if find wrong or error glad fix it!


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -