user2026178
user2026178

Reputation: 318

Application pushed to heroku but not working due to dotenv gem

I have pushed to heroku but the application will not run. I see that it is due to the dotenv gem. Is there a way around this? I need the dot-env gem in order to encrypt the basic auth user name and password. I'd prefer not to use devise or anything of that complexity as this is a simple application.

Below is my heroku terminal output, only issue is I dont really know how to spot errors/read the output.

  /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

Upvotes: 2

Views: 1393

Answers (3)

Simone Carletti
Simone Carletti

Reputation: 176522

You configured the dotenv gem to be enabled only for the development and test environments:

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

However, the application is started in production environment in Heroku. Therefore, the Rails application will crash because it tries to load the gem but it's not available.

You likely manually included the dotenv loading code somewhere in your application:

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

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. If you need it to be initialized sooner, you can manually call Dotenv::Railtie.load.

Upvotes: 3

margo
margo

Reputation: 2927

dotenv is for managing your environment variables in your development environment. YOu need to manually create these variables on heroku.

Upvotes: 1

Hardik Upadhyay
Hardik Upadhyay

Reputation: 2659

dotenv gem is used for load environment variables from .env into ENV in development.

and heroku used production environment. So, you need to just put this on Gemfile

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

Hope, this will helps you.

Upvotes: 1

Related Questions