【发布时间】:2017-06-14 13:34:23
【问题描述】:
我使用 dotenv 来存储环境变量,自从我将它包含在 gemfile 中后,我就无法将它推送到 heroku。我收到以下错误:-
remote: -----> Installing node-v6.10.0-linux-x64
remote: -----> Detecting rake tasks
remote: sh: 2: Syntax error: Unterminated quoted string
remote: sh: 2: Syntax error: Unterminated quoted string
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! rake aborted!
remote: ! NameError: uninitialized constant Dotenv
remote: ! /tmp/build_5437bc300afb80cfa46b1111bb960f46/config/application.rb:17:in `<top (required)>'
remote: ! /tmp/build_5437bc300afb80cfa46b1111bb960f46/Rakefile:4:in `require_relative'
remote: ! /tmp/build_5437bc300afb80cfa46b1111bb960f46/Rakefile:4:in `<top (required)>'
这就是我在 gemfile 中包含 dotenv 的方式:-
gem 'dotenv-rails', :require => 'dotenv/rails-now'
我也尝试在 application.rb 文件中添加以下内容:-
Bundler.require(*Rails.groups)
Dotenv::Railtie.load
HOSTNAME = ENV['HOSTNAME']
还是不行。
我不知道说“未终止的引用字符串”的那两行是否可能是一些不相关的问题,导致 dotenv 无法加载。我查了一下并检查了 heroku 配置,看看变量中是否有问题,但它们看起来都很好。在将 dotenv 添加到 gemfile 之前,我能够推送。
我尝试运行 bundle install、重新启动服务器、删除 gemfile.lock 并运行 bundle install,我在此处查看了此问题并尝试了 Can't push to Heroku because of DOTENV uninitialized constant error 中建议的解决方案
还是没有运气。
PS - 我正在尝试实现 recaptcha,建议最佳做法是使用 dotenv 将 recaptcha 的 site_key 和 secret_key 存储为 env vars。因此,我正试图让它发挥作用。
【问题讨论】:
标签: ruby-on-rails heroku