gpt4 book ai didi

ruby-on-rails - 应用程序已推送到 heroku 但由于 dotenv gem 而无法工作

转载 作者:行者123 更新时间:2023-12-02 04:07:24 25 4
gpt4 key购买 nike

我已推送到heroku,但应用程序无法运行。我发现这是由于 dotenv gem 造成的。有没有解决的办法?我需要 dot-env gem 来加密基本身份验证用户名和密码。我不想使用设计或任何复杂的东西,因为这是一个简单的应用程序。

下面是我的 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 配置为仅针对 开发测试 环境启用:

gem 'dotenv-rails', :groups => [:development, :test]

但是,应用程序是在 Heroku 的生产环境中启动的。因此,Rails 应用程序将崩溃,因为它尝试加载 gem 但它不可用。

您可能在应用程序中的某个位置手动添加了 dotenv 加载代码:

Dotenv::Railtie.load

您需要删除它(因为 dotenv 会在加载 gem 时在加载过程中注入(inject)自身),或者将代码包装在条件 block 中,仅当定义了 Dotenv 时才执行它

if defined? Dotenv
# ..
end

除非您确实需要手动加载库(通常不需要),则只需删除显式语句 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. If you need it to be initialized sooner, you can manually call Dotenv::Railtie.load.

关于ruby-on-rails - 应用程序已推送到 heroku 但由于 dotenv gem 而无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38830828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com