我简直无法忘记这个信息:

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

我有Rails 5.2.0,并运行了

EDITOR=vim rails credentials:edit

里面:

production:
   secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx

保存并在终端中:

RAILS_ENV=production rails c

我错过什么了吗?我重新启动了服务器,遇到了同样的问题,但在开发模式下没有问题.

推荐答案

保留默认的secrets.yml文件

# config/secrets.yml
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  aws_secret: abcde
  some_password: abcdex

development:
  secret_key_base: static_secret_key
  aws_secret: abcde

test:
  secret_key_base: static_test_secret_key


#not_indented: key for all env in once
secret_key_base: global_key_for_all_env
RAILS_ENV=production SECRET_KEY_BASE=production_test_key rails c

如果使用Rails 5.2.0,请添加到下面的production env,选中此LINK

config.require_master_key = true    #config/environments/production.rb

Ruby-on-rails相关问答推荐

在Ruby on Rails中获取堆栈级别太深错误(&Q)

包含字母和数字组合的正则表达式

我可以向 erb 变量插值添加一个类吗?

如何不需要rails/all?

Ruby on Rails/Activerecord 排序自引用查询?

如何保持 en.yml DRY?

正确更新其他列的更新列

错误原始错误:未安装 ImageMagick/GraphicsMagick

Time.zone.now.to_date 是否等同于 Date.today?

骨干model.destroy()即使工作正常也会调用错误回调函数?

如何在两个日期之间生成随机日期和时间?

Rails:设计:按角色登录后重定向

Rails:文件路径

不带参数的 request.fullpath

如何找出现有 Rails 应用程序基于哪个 Rails 版本?

如何显示 RSpec 测试生成的 SQL 查询日志(log)?

Rails Active Admin css 与 Twitter Bootstrap css 冲突

设计自定义路由和登录页面

将图标添加到 Rails 应用程序

何时(如果)合并 ActiveRecord 迁移?