我不明白为什么找不到我的secret_key_base。当我在制作中启动我的应用时,我会在网络浏览器上收到此消息:Missing 'secret_key_base' for 'production' environment, set this value in 'config/secrets.yml'
我的config/secret.yml
看起来像这样:
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
当我用生成的密钥替换<%= ENV["SECRET_KEY_BASE"] %>
时,它会起作用,否则,建议不要......
所以我把钥匙放在/etc/profile
&amp; ~/.bashrc
&amp; ~/.rvm/environment/ruby-2.1.5
如下:
export SECRET_KEY_BASE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
当我在生产模式下启动rails控制台时,我可以看到我的密钥:
rails c production
Loading production environment (Rails 4.1.6)
2.1.5 :001 > ENV["SECRET_KEY_BASE"]
=> "XXXXXXXXXXXXXXXXXXXXX"
我不明白为什么它不知道所有这一切。我错过了一些明显的东西吗?
完整的错误日志:
ERROR RuntimeError: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`
/home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb:462:in `validate_secret_key_config!'
/home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb:195:in `env_config'
/home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/engine.rb:510:in `call'
/home/xxx/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
/home/xxx/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
/home/xxx/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/home/xxx/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/home/xxx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/xxx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/xxx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
编辑1:
我查看了~/.rvm/gems/ruby-2.1.5/gems/railties-4.1.6/lib/rails/application.rb
并使用puts
进行了一些调试跟踪。对于此文件中的Ruby,我的ENV变量看起来像nil
,而在解析文件时看起来也是config/secret.yml
。
以下是我在解析过程中放在文件上的日志:
secrets = ActiveSupport::OrderedOptions.new
yaml = config.paths["config/secrets"].first
if File.exist?(yaml)
puts "FILE EXIST !"
puts ENV["SECRET_KEY_BASE"]
require "erb"
all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {}
puts all_secrets.inspect
env_secrets = all_secrets[Rails.env]
puts env_secrets.inspect
secrets.merge!(env_secrets.symbolize_keys) if env_secrets
puts secrets.inspect
end
以下是使用rvmsudo rails启动服务器时的结果s -e“production”-p 80
FILE EXIST !
<-------------- (nil)
{"development"=>{"secret_key_base"=>"OK"}, "test"=>{"secret_key_base"=>"OK"}, "production"=>{"secret_key_base"=>nil}}
{"secret_key_base"=>nil}
{:secret_key_base=>nil}
看起来rvmsudo没有传递env变量,我会看看它......