[英]Application pushed to heroku but not working due to dotenv gem
I have pushed to heroku but the application will not run. 我已推送到heroku,但该应用程序将无法运行。 I see that it is due to the dotenv gem.
我看到这是由于dotenv宝石造成的。 Is there a way around this?
有没有解决的办法? I need the dot-env gem in order to encrypt the basic auth user name and password.
我需要dot-env gem来加密基本身份验证用户名和密码。 I'd prefer not to use devise or anything of that complexity as this is a simple application.
我宁愿不要使用devise或那样复杂的东西,因为这是一个简单的应用程序。
Below is my heroku terminal output, only issue is I dont really know how to spot errors/read the output. 下面是我的heroku终端输出,唯一的问题是我真的不知道如何发现错误/读取输出。
/app/config/application.rb:4:in `require': cannot load such file -- dotenv (LoadError)
from /app/config/application.rb:4:in `<top (required)>'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:141:in `require'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:141:in `require_application_and_environment!'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:67:in `console'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /app/bin/rails:9:in `require'
from /app/bin/rails:9:in `<main>'
gem 'rails', '4.2.5'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'will_paginate', '~> 3.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem "font-awesome-rails"
gem 'dotenv-rails', :groups => [:development, :test]
gem 'will_paginate-bootstrap'
gem "paperclip", "~> 5.0.0"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# gem 'dotenv-heroku'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
dotenv
gem is used for load environment variables from .env into ENV in development
. dotenv
gem用于将环境变量从.env加载到正在development
ENV中。
and heroku used production
environment. 和heroku使用的
production
环境。 So, you need to just put this on Gemfile
因此,您只需将其放在
Gemfile
gem 'dotenv-rails', :groups => [:development, :test]
Hope, this will helps you. 希望对您有帮助。
dotenv is for managing your environment variables in your development environment. dotenv用于在开发环境中管理环境变量。 YOu need to manually create these variables on heroku.
您需要在heroku上手动创建这些变量。
You configured the dotenv
gem to be enabled only for the development
and test
environments: 您
dotenv
gem配置为仅在development
和test
环境中启用:
gem 'dotenv-rails', :groups => [:development, :test]
However, the application is started in production
environment in Heroku. 但是,该应用程序是在Heroku的
production
环境中启动的。 Therefore, the Rails application will crash because it tries to load the gem but it's not available. 因此,Rails应用程序将因尝试加载gem而崩溃,但它不可用。
You likely manually included the dotenv
loading code somewhere in your application: 您可能在应用程序中的某处手动添加了
dotenv
加载代码:
Dotenv::Railtie.load
You need to remove it (as dotenv will inject itself in the load process, when the gem is loaded), or wrap the code within a conditional block that executes it only if Dotenv
is defined 您需要删除它(因为dotenv会在加载gem时在加载过程中注入自身),或者将代码包装在仅定义了
Dotenv
的情况下才执行它的条件块中
if defined? Dotenv
# ..
end
Unless you really need to manually load the library (and generally you don't), then simply remove the explicit statement, explained in the documentation . 除非确实需要手动加载库(通常不需要),否则只需删除显式语句( 如文档所述) 。
dotenv is initialized in your Rails app during the before_configuration callback, which is fired when the Application constant is defined in config/application.rb with class Application < Rails::Application.
dotenv是在before_configuration回调期间在Rails应用程序中初始化的,当在config / application.rb中使用Application <Rails :: Application类定义Application常量时会触发该操作。 If you need it to be initialized sooner, you can manually call Dotenv::Railtie.load.
如果您需要尽快对其进行初始化,则可以手动调用Dotenv :: Railtie.load。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.