在生产中无法识别 rails secret_key_base [英] rails secret_key_base not being recognized in production

查看:40
本文介绍了在生产中无法识别 rails secret_key_base的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试在生产中部署我的 rails 应用程序.当我转到该页面时,出现 500 错误.当我转到错误日志时,出现以下错误:

So I am trying to deploy my rails app in production. When I go to the page I get a 500 error. When I go to my error logs I get the following error:

Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) 

我正在运行 Rails 4.1,我的 config/secrets.yml 如下所示:

I am running Rails 4.1 and my config/secrets.yml looks like this:

    development:
      secret_key_base: <development key>        
    test:
      secret_key_base: <test key>

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

我运行 rake secret 以获取密钥并将导出内容放入我的 bash_profile 并获取它.我运行了 rake assets:precompile 成功.但是我仍然不断收到此错误.有什么想法吗?

I ran rake secret to get the key and put the export in my bash_profile and sourced it. I ran rake assets:precompile successfully. Yet I still keep getting this error. Any ideas?

更新:我尝试更新提供的错误消息以提供更好的信息......但消息没有更新.然后我尝试将密钥直接添加到 yml 文件而不是使用环境变量,但仍然没有骰子.我在 hostmonster 上运行,所以我无法重新启动服务器.....但是有些事情告诉我这就是需要做的事情...

Update: I tried to update the error message provided to give slightly better information....and the message didn't update. I then tried adding the key directly to the yml file instead of using an environment variable and still no dice. Im running on hostmonster so I can't restart the server.....but something is telling me thats what needs to be done...

更新 2:睡了一夜之后,这个问题似乎不再是问题了.它一定是某种缓存.现在我的问题是它试图使用我几天前为我的数据库更改的旧配置.如果我弄清楚如何使缓存无效,我会将其发布在这里并将其标记为答案.如果其他人知道该怎么做,请告诉我,我会将其标记为答案.我使用 HostMonster 作为我的主机,并按照他们网站上的步骤来托管我的 Rails 应用程序.

Update 2: After sleeping through the night it seems that this issue is no longer an issue. It must have been some sort of caching. Now my issue is that its trying to use an old config that i changed days ago for my database. If I figure out how to nullify the cache I will post it here and mark it as an answer. If someone else knows how to do it please let me know and I will mark it as an answer. I am using HostMonster as my hosting and followed the steps they have on their site for hosting my rails app.

推荐答案

  1. 您需要重新启动服务器,因为在 config/environment.rb 中调用 YourAppName::Application.initialize! 之后,您将无法更改设置.
  2. 检查你的 yml 标记,可能有一些错误
  3. 可能是你的 config/initializers/secret_token.rb 有问题
  1. You need to restart your server, because after YourAppName::Application.initialize! called in config/environment.rb you can not change your settings.
  2. Checkout your yml markup, probably there some errors
  3. Probably something wrong in your config/initializers/secret_token.rb

问题不在于 ENV 伪哈希.如果在 ENV 中没有这样的密钥,secret_key_base 将为 nil.

The problem is not with ENV pseudo-hash. secret_key_base will be nil if in ENV no such a key.

这篇关于在生产中无法识别 rails secret_key_base的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆