简体   繁体   English

Gemfile中的Ruby版本

[英]Ruby version in the Gemfile

The Ruby on Rails Tutorial by Michael Hartl uses a Gemfile without specifying a Ruby version: the ruby keyword is missing in all the applications. Michael Hartl的Ruby on Rails教程使用Gemfile而没有指定Ruby版本:所有应用程序中都缺少ruby关键字。

When I deploy to Heroku I receive the following warning: 当我部署到Heroku时,我收到以下警告:

remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.2.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.

The tutorial says that " the costs associated with including such an explicit Ruby version number outweigh the (negligible) benefits, so you should ignore this warning for now. The main issue is that keeping your sample app and system in sync with the latest Ruby version can be a huge inconvenience ". 该教程说与包含这样一个显式Ruby版本号相关的成本超过了(可忽略的)优势,所以你现在应该忽略这个警告。主要问题是保持你的示例应用程序和系统与最新的Ruby版本同步可能是一个巨大的不便 “。

I am wondering whether the alternative is to keep the pace with the Ruby version at Heroku (presumably 2.2.4 at present), as the book seems to suggest, or also to specify any Ruby version it suits me. 我想知道是否可以选择在Heroku上保持Ruby版本的速度(目前大概是2.2.4),正如本书似乎暗示的那样,或者也指出任何适合我的Ruby版本。 In other words, since I am using Ruby 2.2.1p85 for my application, adding ruby "2.2.1", :patchlevel => "85" would work and make Heroku adjust to this version or rather I am supposed to adjust to Heroku and add as suggested ruby '2.2.4' ? 换句话说,因为我使用Ruby 2.2.1p85作为我的应用程序,添加ruby "2.2.1", :patchlevel => "85"将起作用并使Heroku适应此版本或者更确切地说我应该适应Heroku和添加建议ruby '2.2.4'

I am using rvm and a specific gemset with a specific Ruby version, for no other reason than trying to use an environment as much close to the tutorial as possible. 我正在使用rvm和具有特定Ruby版本的特定gemset,除了尝试使用尽可能接近教程的环境之外别无他法。 What is the best practice in a real context? 真实环境中的最佳实践是什么? Would you suggest to use the last Ruby version and include it in the Gemfile? 您是否建议使用最新的Ruby版本并将其包含在Gemfile中? Can the Gemfile leave out the Ruby version with no worries? Gemfile可以省去Ruby版本而不用担心吗?

Please follow the steps to solve You can check which ruby version is associate with your app by command 请按照步骤解决您可以通过命令检查哪个ruby版本与您的应用程序相关联

heroku run "ruby -v"

It is good to have default version of ruby which is 2.2.4 in order to solve your problem. 为了解决您的问题,最好使用2.2.4默认版本ruby If your ruby version is older than 2.2.4 then please upgrade it. 如果您的ruby版本早于2.2.4那么请升级它。

after checking/upgrading version You can use the ruby keyword in your app's Gemfile to specify a particular version of Ruby. 检查/升级版本之后您可以在应用程序的Gemfile使用ruby关键字来指定特定版本的Ruby。

source "https://rubygems.org"
ruby "2.2.4"

You will need to install and update bundler again 您需要再次安装和更新bundler

$ gem install bundler
$ bundle update

This command: 这个命令:

heroku run rake db:migrate

solved same problem 解决了同样的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM