我该如何将Rails 4.2.7.1升级到Rails 5.0.0.1?

8

我正在使用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 命令,而不是 install(update 获取新的 gem 包,install 会匹配你的 Gemfile.lock 文件),因为你需要新版本的 gem 包(特别是 activerecord-import 0.11.0 或更高版本)来解决依赖关系。然后按照下面建议的升级指南进行操作。 - Doon
正如我在问题中提到的那样,在运行“bundle install”之前,我删除了“Gemfile.lock”文件。然而,即使将其保留并运行“bundle update”,仍会出现相同的错误。 - Dave
是的,错过了删除.lock文件的步骤。你验证过所有的gem都支持Rails 5吗? - Doon
看起来这是uuids gem。uuids被解析为0.0.1,它依赖于rails(~> 4.1)~>的意思是> 4.1 and < 5.0。所以目前正在阻塞。我似乎找不到它的主页(最新版本是从1/15)。 - Doon
在4.2及更早版本上运行rake rails:update - Bandi
显示剩余2条评论
4个回答

2

感谢您的回复,但是当我运行该命令时,出现了错误:“错误:未识别命令'app:update'”。完整的输出结果已在我的问题中编辑。 - Dave
你现在只是猜测吗?我运行了那个命令,被要求覆盖一堆文件,然后我运行了“rails -v”,得到了“Rails 4.2.7.1”,所以没有任何改变。 - Dave
不,我不是在猜测。它在括号里的文档中有说明(在4.2及早期版本上运行rake rails:update)。请参阅升级Ruby on Rails文档中的1.4节。 - jhack

1

有一篇文章介绍了如何升级Rails和Rails应用程序 更新到Rails 5.0。你应该先升级本地的ruby和rails版本,然后再升级你的应用程序。

但是在将应用程序更新到Rails 5之后,你可能需要进行一些更改。还有另一篇文章介绍了如何做到这一点 Rails升级清单


尝试过了,但没有成功。在文章中的哪个具体步骤可以克服错误“Bundler无法找到与gem“activerecord”兼容的版本”? - Dave
我建议您按照本文中的所有步骤进行操作。 - Kirill Zhuravlov

1
你需要找到uuids gem的替代品,因为即使是最新版本的uuids也需要hexx-active_record,而后者需要activerecord < 5,而rails5需要activerecord 5。此外,hexx-active_record gem在rubygems上不可用。请查看此链接https://www.versioneye.com/ruby/hexx-active_record/6.1.0
因此,目前唯一的解决方案是寻找uuids的替代品。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接