3

I'd like to use a specific version of ruby when running my app in production on Heroku.

As explained here, you only have to add a line like ruby "2.0.0" in your Gemfile.

However, as I use RVM locally, I already specified the ruby version to use in a .ruby-version file in the root directory of the project that only contains the line ruby-2.0.0-p0.

To avoid code duplication, I'd like the version to be specified in only one place, so that I'm sure that the same version is always used in development and on Heroku.

Is there a way to do that ?

4

2 回答 2

6

Gemfile是 ruby​​ 代码,因此您可以编写一些 ruby​​ 来读取版本.ruby-version并将该值传递给ruby方法,而不是硬编码的版本字符串。

如果.ruby-version文件在同一个目录中,这样的事情应该可以工作:

ruby File.read(".ruby-version").strip.split("-").first

例如,如果.ruby-version文件包含“1.9.3-p327”,则该行相当于:

ruby "1.9.3"
于 2013-10-01T16:40:47.660 回答
0

不,您不能指定要在 Heroku 上使用的补丁级别 - 它们会为您管理补丁级别。您需要跟踪他们的更改日志以了解补丁级别何时更改。所以你需要确保你在本地使用相同的补丁级别,对于 Ruby 2.0.0,它存在 p195。

于 2013-06-03T10:11:30.633 回答