Rails: How to fix “Missing secret_key_base for 'production' environment”

前端 未结 8 1825
野趣味
野趣味 2020-12-15 16:33

I simply can\'t get past the message:

Missing `secret_key_base` for \'production\' environment, set this string with `rails credentials:edit` (ArgumentError)         


        
相关标签:
8条回答
  • 2020-12-15 17:05

    Secret_key_base isn't properly setting. It's a known issue not getting enough attention: https://github.com/rails/rails/issues/32947

    Generate the keys with:

    EDITOR=vim rails credentials:edit
    

    Record the key. Save in config/master.key.

    SECRET_KEY_BASE=`cat config/master.key` bin/rails assets:precompile
    

    This is the solution I came to. I really don't like how I've been forced to put it though an environment variable. If someone has more information to bring to my attention on how master.key and such work, please do comment.

    0 讨论(0)
  • 2020-12-15 17:05

    I ran into this problem when deploying my rails app to dokku using a Dockerfile. My solution:

    the file config/secrets.yml references an environment variable:

    production:
      secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
    

    I need to set this variable using the dokku command line (either directly on the server, or using the dokku-cli gem on my development machine):

    dokku config:set SECRET_KEY_BASE=blalbalblablahblablah
    
    0 讨论(0)
提交回复
热议问题