在windows上开发,在heroku上运行独角兽

Jos*_*eph 16 git ruby-on-rails heroku bundler

我有一个新的Rails项目,我决定尝试heroku,部署似乎很容易

我正在开发Windows,所以运行独角兽不是一个选择,但webrick可以用于开发

但是,当它部署时,我想使用独角兽,而heroku完全支持这一点

问题是:我必须在我的Gemfile上列出独角兽以便heroku选择它,但是当我这样做并在我的windows dev机器上运行bundle命令(或rails s)时,它会尝试安装unicorn服务器

我试图把独角兽放在生产组,组:生产做宝石'独角兽'结束仍然捆绑抱怨,我无法运行开发服务器

jig*_*fox 42

您可以在Gemfile中定位特定平台:

platforms :ruby do # linux
  gem 'unicorn'
end

platforms :mswin do
  # gems specific to windows
end
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅gemfile联机帮助页.


Fel*_*lix 16

替代解决方案(原始海报非常接近)是

group :production do
  gem 'unicorn'
end
Run Code Online (Sandbox Code Playgroud)

然后使用

bundle install --without production
Run Code Online (Sandbox Code Playgroud)

在您的Windows机器上.

Heroku旁注(未测试)

与接受的答案不同,这不应该导致Heroku忽略你的 Gemfile.lock

这是因为Heroku检查你的Gemfile mswin以及mingw何时决定它是否是Windows生成的.