【问题标题】:How do I upgrade from Rails 4.2.7.1 to Rails 5.0.0.1?如何从 Rails 4.2.7.1 升级到 Rails 5.0.0.1?
【发布时间】:2016-10-14 14:12:31
【问题描述】:

我正在使用 4.2.7.1,我想升级到 Rails 5.0.0.1。所以我像这样调整了我的 Gemfile

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0.1’
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'

gem 'uuids'
gem 'addressable'
gem 'postgresql'
gem 'pundit'
gem 'omniauth-oauth2', '~> 1.3.1'
gem 'omniauth-google-oauth2'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'omniauth-linkedin-oauth2'
gem 'jquery-ui-rails'
gem 'will_paginate'
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
gem 'compass-rails'
gem 'pdf-reader'
gem 'jquery-turbolinks'
gem 'tor', :git => 'https://github.com/dryruby/tor.rb.git'
gem 'tor_requests'
gem 'tor-privoxy'
gem 'net-telnet'
gem 'mechanize'
gem 'activerecord-import'

但是当我尝试运行“bundle install”(删除 Gemfile.lock 之后)时,我得到了这些错误......

localhost:myproject davea$ bundle install
Fetching https://github.com/dryruby/tor.rb.git
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies.................................................
Bundler could not find compatible versions for gem "activerecord":
  In Gemfile:
    activerecord-import was resolved to 0.16.1, which depends on
      activerecord (>= 3.2)

    rails (~> 5.0.0.1) was resolved to 5.0.0.1, which depends on
      activerecord (= 5.0.0.1)

    uuids was resolved to 1.4.0, which depends on
      activerecord (~> 4.1)
Bundler could not find compatible versions for gem "hexx-active_record":
  In Gemfile:
    uuids was resolved to 4.0.0, which depends on
      hexx-active_record (~> 1.3)

Could not find gem 'hexx-active_record (~> 1.3)', which is required by gem 'uuids', in any of the sources.Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (~> 5.0.0.1)

    uuids was resolved to 0.0.1, which depends on
      rails (~> 4.1)

我需要做什么来升级我的 Rails 版本?

编辑:响应给出的答案输出

localhost:myproject davea$ rails app:update
Error: Command 'app:update' not recognized
Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 dbconsole   Start a console for the database specified in config/database.yml
             (short-cut alias: "db")
 new         Create a new Rails application. "rails new my_app" creates a
             new application called MyApp in "./my_app"

In addition to those, there are:
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 plugin new   Generates skeleton for developing a Rails plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")

All commands can be run with -h (or --help) for more information.

【问题讨论】:

  • 你需要bundle update,而不是安装(更新获取新的gem,安装匹配你的gemfile.lock)。因为你需要新版本的gem(特别是activerecord-import 0.11.0或更大)来解决这种依赖关系。然后按照下面建议的升级指南进行操作
  • 正如我在问题中提到的,我在运行“捆绑安装”之前删除了“Gemfile.lock”问题。尽管如此,将其保留在那里并运行“捆绑更新”会导致相同的错误。
  • 是的,错过了删除 .lock 文件。您是否已验证您的所有 gem 都与 rails 5 兼容
  • 不,有没有一种程序化的方式来做到这一点,或者我只是去每个站点并尝试破译他们的文档?
  • 它看起来像是 uuids gem。 uuids was resolved to 0.0.1, which depends on rails (~> 4.1)~> 表示 > 4.1 and < 5.0。所以它目前正在阻塞。我似乎找不到它的主页(最新版本是从 1/15 开始)。

标签: ruby-on-rails ruby-on-rails-4 rubygems upgrade gemfile


【解决方案1】:

从 Ruby on Rails 文档看来,rails app:update 将帮助您从 rails 4 更新到 5。

http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html

【讨论】:

  • 谢谢,但是当我运行命令时出现错误,“错误:命令 'app:update' 无法识别”。完整的输出正在对我的问题进行编辑。
  • 你现在只是在猜测吗?我运行了那个命令,被要求覆盖一堆文件,然后我运行“rails -v”,得到“Rails 4.2.7.1”,所以什么都没有改变。
  • 不,我没猜。它在括号中的文档中。 (耙轨:更新 4.2 及更早版本)。升级 ruby​​ on rails 文档中的第 1.4 节。
【解决方案2】:

有一篇关于如何升级rails和rails_app的文章Updating to Rails 5.0 您应该先升级您的本地 ruby​​ 和 rails 版本,然后再升级您的应用程序。

但是在将您的应用程序更新到 rails 5 之后,您可能应该进行一些更改。还有一篇关于如何做到这一点的文章Rails Upgrade Checklist

【讨论】:

  • 试过了,没用。文章中的哪些具体步骤克服了错误“Bundler 找不到 gem “activerecord”的兼容版本”?
  • 我建议您完成本文中的所有步骤
【解决方案3】:

在找到 uuids gem 的替代品之前,你不能这样做,因为即使是最新版本的 uuids 也需要 hexx-active_record ,它需要 activerecord https://www.versioneye.com/ruby/hexx-active_record/6.1.0。

所以目前唯一的解决方案是找到 uuids 的替代品

【讨论】:

    【解决方案4】:

    我想这是最好的http://railsapps.github.io/updating-rails.html,但你应该在升级之前检查你的测试。

    【讨论】:

      猜你喜欢
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      相关资源
      最近更新 更多