Ruby-on-rails “开发”环境缺少“secret_token”和“secret_key_base”,请在“config/secrets.yml”中设置这些值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32397607/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:03:35  来源:igfitidea点击:

Missing `secret_token` and `secret_key_base` for 'development' environment, set these values in `config/secrets.yml`

ruby-on-railsrubyruby-on-rails-4

提问by Alex Shmatko

When I try to run rails servercommand I get the error

当我尝试运行rails server命令时出现错误

enter image description here

在此处输入图片说明

How to solve it?

如何解决?

My config/environments/development.rb

我的配置/环境/development.rb

Rails.application.configure do

  config.secret_key_base = ENV["SECRET_KEY_BASE"]

  #Some stuff 

end

And I don't have the secret.ymlfile in my folder.

而且我的文件夹中没有secret.yml文件。

enter image description here

在此处输入图片说明

回答by ddavison

Then create one:

然后创建一个:

config/secrets.yml

配置/secrets.yml

# be sure to restart your server when you modify this file...
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
development:
  secret_key_base:  asdflkjasdlfkjasldfkj

test:
  secret_key_base:  asdflkhasldfhlhaskdlflakhsdf

production:
  secret_key_base: 523lk5h2lkjlj6nlk4n6lk4

obviously don't use those keys above ^ just mash on your keyboard, or use rake secretto generate one :)

显然不要使用上面的那些键 ^ 只是在你的键盘上混搭,或者rake secret用来生成一个:)

回答by Aleksandar Pavi?

You skipped one installation step.

您跳过了一个安装步骤。

For Redmine 2 and 3 versions, type:

对于 Redmine 2 和 3 版本,键入:

RAILS_ENV=production bundle exec rake generate_secret_token

回答by Atchutha rama reddy Karri

The following solution helped me:

以下解决方案帮助了我:

Create a secrets.yml file in your config directory.

在您的 config 目录中创建一个 secrets.yml 文件。

In your terminal, type the following command: rake secret. This will generate a secret for you to include in your secrets.yml file.

在您的终端中,键入以下命令:rake secret。这将生成一个秘密供您包含在您的 secrets.yml 文件中。

Add the following snippet of code to your config/secrets.yml file:

将以下代码片段添加到您的 config/secrets.yml 文件中:

development: secret_key_base: PASTE_YOUR_GENERATED_SECRET_HERE

开发:secret_key_base:PASTE_YOUR_GENERATED_SECRET_HERE

回答by Esmaeil MIRZAEE

My solution to the problem is creating a new project then copy the 'secrets.yml` from the newly generated app into the old project.

我对这个问题的解决方案是创建一个新项目,然后将“secrets.yml”从新生成的应用程序复制到旧项目中。

rails new TmpApp

cd TmpApp/config

cp secrets.yml /Path/to/old/project/config/

回答by Douglas G. Allen

I encountered this same issue with Redmine. There is a Rake task to generate it. It does not need to go into a Yaml file. It goes into a secret_tocken.rb file in the initializers folder.

我在 Redmine 中遇到了同样的问题。有一个 Rake 任务来生成它。它不需要进入 Yaml 文件。它进入 initializers 文件夹中的 secret_token.rb 文件。