首页 > 解决方案 > Rails 3.2 到 4.0 升级问题

问题描述

我是 ruby​​ on rails 的新手,正在尝试将具有 rails 版本 3.2 的遗留项目升级到 4.0。我正在逐步升级版本以达到 rails 6 版本。我将 gem 文件中的 rails 版本更改为 4.0(gem lock 有旧版本 3.2)并执行命令 bundle update rails。它给了我 mongoid_rails_integrations 的以下错误。

    Bundler could not find compatible versions for gem "json":
  In Gemfile:
    json

    aws-sdk (~> 1.34.1) was resolved to 1.34.1, which depends on
      json (~> 1.4)

    carrierwave-video was resolved to 0.5.6, which depends on
      carrierwave was resolved to 0.11.2, which depends on
        json (>= 1.7)

    mongoid-simple-tags was resolved to 0.1.3, which depends on
      json (~> 1.8)

    simplecov was resolved to 0.13.0, which depends on
      json (>= 1.8, < 3)

Bundler could not find compatible versions for gem "mongoid":
  In snapshot (Gemfile.lock):
    mongoid (= 3.1.7)

  In Gemfile:
    mongoid-rspec (>= 1.4.6) was resolved to 1.13.0, which depends on
      mongoid (~> 3.1)

    mongoid_rails_migrations was resolved to 1.2.1, which depends on
      mongoid (>= 4.0.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (= 4.0.0)

    mongoid_rails_migrations was resolved to 1.0.1, which depends on
      rails (>= 3.2.0)

Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    rails (= 4.0.0) was resolved to 4.0.0, which depends on
      railties (= 4.0.0)

    sass-rails (~> 3.2.3) was resolved to 3.2.6, which depends on
      railties (~> 3.2.0)

但我的问题是 mongoid_rails_migrations 取决于大于 3.2 的 rails 版本,这适用于 rails 4.0 。那么为什么会出现这个错误。任何人请帮助我弄清楚将是可观的。

标签: ruby-on-railsrubymongoid

解决方案


在当前的升级尝试中,您有许多相互冲突的要求。我建议从更容易修复的开始,然后回到轨道。

aws-sdk (~> 1.34.1) was resolved to 1.34.1, which depends on
  json (~> 1.4)

首先尝试放松 aws-sdk 版本,以便您可以使用 json 1.8。

sass-rails (~> 3.2.3) was resolved to 3.2.6, which depends on
  railties (~> 3.2.0)

尝试放松 sass-rails 版本,以便这部分消失。

mongoid-rspec (>= 1.4.6) was resolved to 1.13.0, which depends on
  mongoid (~> 3.1)

mongoid_rails_migrations was resolved to 1.2.1, which depends on
  mongoid (>= 4.0.0)

这可能是一个问题,但首先要处理我之前提到的东西。

最初我认为您可能需要同时更新 rails、active* 和 railties,因为它们的版本已锁定。当前消息不一定表明这一点,但您仍然可以尝试尝试一下。

我需要在安装前删除gem lock吗

不建议。您可能会获得满足 gemfile 中破坏您的应用程序的约束的更新。当一个人尝试像这样更新一个古老的应用程序时,有意识地考虑每一个依赖项以及其版本更改可能产生的影响通常是一个非常好的主意。


推荐阅读