Deploying to Heroku with environment variables in Gemfile

谁说我不能喝 提交于 2019-12-12 05:53:53

问题


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?


回答1:


Wrap the conditional in a group and try to BUNDLE_WITHOUT on deployment. ref

group :byebug do
  if ENV["USE_DEBUGGER"]
    gem "pry-byebug"
    gem "byebug"
  end
end

heroku config:add BUNDLE_WITHOUT="byebug"




回答2:


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.



来源:https://stackoverflow.com/questions/28172715/deploying-to-heroku-with-environment-variables-in-gemfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!