Rails 4.0.5 secret.yml配置

时间:2014-06-27 02:06:03

标签: ruby-on-rails ruby configuration-files

所以我试图让我的第一个ruby在rails app上运行并且在第一次运行“rails s”之后,当我导航到localhost时,我得到以下消息:3000:

  

内部服务器错误

     

您必须在应用的配置中设置config.secret_key_base。

我做了一些研究,看起来我需要配置我的secrets.yml文件,但不确定它应该是什么样子。这就是我的secrets.yml文件的样子:

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa



test:
  secret_key_base: fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa


# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

开发和测试secret_key_base来自我运行“rake secret”时生成的密钥。

我应该把什么放在制作secret_key_base中(这是我推测的错误)?

编辑:我的config / initializers / secret_token.rb文件应该是什么样的?这就是我的意思:

Demoapp :: Application.config.secret_key_base = fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa

解决方案:我忘记将生成的密钥放在我的config / initializers / secret_token.rb文件中的引号中。 config / initializers / secret_token.rb现在看起来像这样,工作正常:

Demoapp :: Application.config.secret_key_base ='fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa'

1 个答案:

答案 0 :(得分:1)

您应该在承载此生产环境的服务器上添加来自新SECRET_KEY_BASE命令的值的环境变量rake secret。在secrets.yml中,为生产secret_key_base分配了此环境变量SECRET_KEY_BASE的值。

请参阅Environment variable了解有关不同平台主题的信息。

设置环境变量满足要求,您无需修改​​secrets.yml文件。