Ruby-on-rails 弃用警告:您没有设置 config.secret_key_base
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22268669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DEPRECATION WARNING: You didn't set config.secret_key_base
提问by Caleb
I receive this warning when running my specs. Is there a best practice for generating a secret_key_base, or will any string suffice (with regard to security concerns)?
我在运行我的规范时收到这个警告。是否有生成 secret_key_base 的最佳实践,或者任何字符串就足够了(关于安全问题)?
回答by Agis
You propably upgraded to Rails 4 from a 3.x or a previous version.
您可以从 3.x 或以前的版本升级到 Rails 4。
First generate a random secret key value:
首先生成一个随机密钥值:
$ bundle exec rake secret
Then take that value and put it in config/initializers/secret_token.rb:
然后获取该值并将其放入config/initializers/secret_token.rb:
YourApp::Application.config.secret_key_base = 'your-secret'
replacing YourAppwith the name of your application.
替换YourApp为您的应用程序名称。
The reason for this is explained here.
原因在此处解释。
Also see http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml
另见http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml
回答by tamouse
As of 4.1, you need to use the config/secrets.ymlfile. This is discussed in http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml.
从 4.1 开始,您需要使用该config/secrets.yml文件。这在http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml 中进行了讨论。
回答by KyleWilliam
You simply need to create a secret_token.rb file in the config/initializers directory.
您只需要在 config/initializers 目录中创建一个 secret_token.rb 文件。
Contents of the file below:
文件内容如下:
YourAppNameHere::Application.config.secret_key_base = #type the key you generated with rake secret here
then save the file
然后保存文件
close your server:
ctrl c
restart it: rails s
You'll now see the basic rails app page you saw in the last chapter (If you're working through Hartl's tutorial)
您现在将看到您在上一章中看到的基本 Rails 应用程序页面(如果您正在阅读 Hartl 的教程)
回答by Jeff
If you are a total noob like me, remember to put the secret_key_base = 'whatever' inside single quotes. Just a copy and paste without quotes will throw an error :
如果你和我一样是个菜鸟,记得把 secret_key_base = 'whatever' 放在单引号内。仅复制和粘贴不带引号将引发错误:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.8/lib/act ive_support/dependencies.rb:223:in `load': C:/Users/Jeff C/documents/rails_proje cts/first_app/config/initializers/secret_token.rb:1: syntax error, unexpected tI DENTIFIER, expecting $end (SyntaxError)
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.8/lib/active_support/dependencies.rb:223:in `load': C:/Users/Jeff C /documents/rails_proje cts/first_app/config/initializers/secret_token.rb:1: 语法错误,意外的 tI DENTIFIER,期待 $end (SyntaxError)

