Can't push to Heroku because of DOTENV uninitialized constant error
Asked Answered
I

1

3

I am trying to push my project up to Heroku. I have been using:

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

Because I am using recpatcha and need to export my keys to the app in development.

When I try to push the code to heroku I noticed this error message:

    remote:  !     NameError: uninitialized constant Dotenv

So I commented out the Dotenv gem and any Dotenv variables in the app. I ran

    $ bundle exec rake -P

Then tried the push again. I am still getting the same error from Heroku. Do I need to reset my gemfiles somehow?

Intranuclear answered 8/12, 2016 at 9:40 Comment(5)
May be this will help you https://mcmap.net/q/1175039/-set-secret_key_base-in-production-using-a-env-fileJackfruit
The thing is I have dotenv working fine, and I have set my heroku config with the keys, its just that when I push to heroku I get the uninitialized constant error.Intranuclear
see this comment from above mentioned answer: #23439648Jackfruit
I am not sure how to load dotenv into production using an init file, can you explain what is meant there?Intranuclear
Ok. Into your rails_project/cofig/ Create one file and named it dotenv_load.rb Into this new file paste this code require 'dotenv' Dotenv.load. Then find secret_key_base in your project. Copy the value of secret_key_base and paste this into boot.rb like this ENV["SECRET_KEY_BASE"] = "YOUR SECRET KEY BASE"Jackfruit
I
6

Ok, so the answer in the end was that I needed to change

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

to

    gem 'dotenv-rails', :require => 'dotenv/rails-now'

which I think is another way of doing what you were suggesting there @ABPrime. Thanks a lot for your help.

Intranuclear answered 8/12, 2016 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.