NameError:未初始化的常量Dotenv,同时将rails应用程序推送到heroku [英] NameError: uninitialized constant Dotenv while pushing rails app to heroku
问题描述
我使用dotenv存储环境变量,并且自从我将它包含在gemfile中后,我无法将其推送到heroku。我收到以下错误: -
remote:----->安装node-v6.10.0-linux-x64
remote:----->检测rake任务
remote:sh:2:语法错误:未终止的带引号的字符串
remote:sh:2:语法错误:未终止的带引号的字符串
remote:!
remote:!无法检测到rake任务
remote:!确保你可以针对你的应用运行'$ bundle exec rake -P`
remote:!并使用您的Gemfile的生产组。
remote:!耙子中止了!
remote:! NameError:未初始化的常量Dotenv
remote:! /tmp/build_5437bc300afb80cfa46b1111bb960f46/config/application.rb:17:in`< top(required)>'
remote:! / tmp / build_5437bc300afb80cfa46b1111bb960f46 / Rakefile:4:在`require_relative'
remote:! / tmp / build_5437bc300afb80cfa46b1111bb960f46 / Rakefile:4:在<< top(required)>'
我是如何在我的gemfile中包含dotenv的: -
gem'dotenv-rails',:require => 'dotenv / rails-now'
我也尝试在application.rb文件中添加以下内容:
$ b $ pre $ Bundler.require(* Rails.groups)
Dotenv :: Railtie.load
HOSTNAME = ENV ['HOSTNAME']
仍然不起作用。
我不知道这两行是否说未端接的引用字符串可能是导致dotenv无法加载的一些无关的问题。我查了一下并检查了heroku配置文件,看看变量中是否有什么不对劲,但它们都很好。在添加dotenv到gemfile之前,我能够推动。
我试着运行bundle install,重新启动服务器,删除gemfile.lock并运行bundle install,我在这里查看了这个问题,并尝试了由于DOTENV未初始化的常量错误,无法推送到Heroku
仍然没有运气。
PS - 我试图实施recaptcha,建议使用最佳实践dotenv将recaptcha的site_key和secret_key存储为env vars。因此,我试图让这个工作。
我面临同样的问题,并能够解决它与以下。
$ b <1> 在中添加
仅适用于特定环境: dotenv-rails
Gemfile
#Gemfile
group:development,:test do
gem'dotenv-rails'
end
2)只有当环境符合你的 Gemfile
组:
时才运行 Dotenv
#config / application.rb
Bundler.require(* Rails.groups)
if ['development','test']。包括? ENV ['RAILS_ENV']
Dotenv :: Railtie.load
end
I'm using dotenv to store environment variables and ever since I include it in the gemfile I cannot push it to heroku. I'm getting the following error:-
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)>'
This is how I'm including dotenv in my gemfile:-
gem 'dotenv-rails', :require => 'dotenv/rails-now'
I have tried adding the following in the application.rb file as well:-
Bundler.require(*Rails.groups)
Dotenv::Railtie.load
HOSTNAME = ENV['HOSTNAME']
still doesn't work.
I don't know if those two lines that say "unterminated quoted string" could be some unrelated issue leading to the dotenv not loading. I looked it up and checked heroku config to see if there was something amiss in the variables but they all seem fine. I was able to push before I added the dotenv to gemfile.
I tried running bundle install, restarting server, deleting gemfile.lock and running bundle install and I looked this issue up on here and tried solutions suggested in Can't push to Heroku because of DOTENV uninitialized constant error
Still no luck.
PS - I'm trying to implement recaptcha and it is suggested best practice to use dotenv to store the site_key and secret_key for recaptcha as env vars. Hence I'm trying to get this to work.
I faced the same issue and was able to solve it with a following.
1) Add dotenv-rails
in the Gemfile
only for specific environments:
# Gemfile
group :development, :test do
gem 'dotenv-rails'
end
2) And run Dotenv
stuff only if the environment matches your Gemfile
group:
# config/application.rb
Bundler.require(*Rails.groups)
if ['development', 'test'].include? ENV['RAILS_ENV']
Dotenv::Railtie.load
end
这篇关于NameError:未初始化的常量Dotenv,同时将rails应用程序推送到heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!