Search code examples
ruby-on-railsgitherokurubymine

Deploying to Heroku with environment variables in Gemfile


I've recently updated our Gemfile as pry-byebug and bye-bug were causing Rubymine to crash for some of my colleagues. Since there are some of us that use other editors I've added an environment variable to our Gemfile:

if ENV["USE_DEBUGGER"]
  gem "pry-byebug"
  gem "byebug"
end

This worked fine in our local machines but deploying to Heroku causes the following error: gist

I've tried running bundle install and committing a new Gemfile.lock but that changes nothing. Getting rid of the control flow declaration or simply removing the gems fixes the issue.It's worth nothing that in that same commit I bumped the required ruby version to 2.2.0

Is there any way to use conditional statements in the Gemfile without blowing Heroku up?


Solution

  • Alright so after juggling with RubyMine I realised the problem occurs when requireing pry and any other related debugging gems. I managed to fix this by updating my Gemfile to the following:

      if ENV["USE_DEBUGGER"]
        gem "pry-byebug"
        gem "byebug"
      else
        gem "pry-byebug", require: false
        gem "byebug", require: false
      end
    

    I hope this helps anybody facing a similar issue.