You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 6.1升级至7.0.4遭遇Gem依赖兼容问题求助

问题描述

尝试将Rails应用从6.1版本升级至7.0.4版本,更新Gemfile中的Ruby和Rails版本后执行bundle install失败,触发依赖冲突错误。

Gemfile配置

ruby "3.1.2"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem "rails", "~> 7.0.4"
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'

gem 'activerecord', '>= 7.0.4'
gem 'actionpack', '>= 7.0.4'

# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# 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.7'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false

gem 'devise'
gem 'pundit'
gem 'simple_token_authentication'

gem 'autoprefixer-rails'
gem 'font-awesome-sass', '~> 6.1'
gem 'simple_form'

# Charts
gem "chartkick"

# Generateur de PDF
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'wkhtmltopdf-heroku', '2.12.6.0'

# Editeur de texte
gem 'ckeditor', github: 'galetahub/ckeditor'
gem "mini_magick"

gem "select2-rails"
gem 'select2_simple_form', github: 'lndl/select2_simple_form', tag: '0.7.3'

gem 'sidekiq'
gem 'sidekiq-failures', '~> 1.0'

# Cloud Storage
gem "aws-sdk-s3", require: false
gem "down"
gem "image_processing", ">= 1.2"

# transform file via zip
gem 'rubyzip', '>= 1.0.0'
gem 'zip-zip'

# XML reader
gem 'nokogiri', '~> 1.6', '>= 1.6.6.2'

group :development, :test do
  gem 'pry-byebug'
  gem 'pry-rails'
  gem 'dotenv-rails'

  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: %i[mri mingw x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

错误信息

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    rails (~> 7.0.4) was resolved to 7.0.4, which depends on
      actionpack (= 7.0.4)

    simple_token_authentication was resolved to 1.13.0, which depends on
      actionpack (< 5, >= 3.2.6)
Bundler could not find compatible versions for gem "activerecord":
  In Gemfile:
    rails (~> 7.0.4) was resolved to 7.0.4, which depends on
      activerecord (= 7.0.4)

    simple_token_authentication was resolved to 1.5.2, which depends on
      activerecord (< 5, >= 3.2.6)
Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (~> 7.0.4)

    simple_token_authentication was resolved to 1.0.0.pre.beta.2, which depends on
      rails (~> 4.0.0)
解决方案

核心冲突来自simple_token_authentication——官方稳定版本仅支持Rails 3.2到4.x,无法适配Rails 7.0.4,按以下步骤修复:

  • 替换兼容分支
    将Gemfile中的gem 'simple_token_authentication'替换为社区维护的Rails 7兼容分支:

    gem 'simple_token_authentication', github: 'goncalvesjoao/simple_token_authentication', branch: 'rails-7-compatibility'
    
  • 移除冗余依赖
    删除Gemfile中手动声明的activerecord和actionpack版本,这两个是Rails核心组件,会随rails gem自动引入,手动声明易引发冲突:

    # 删掉这两行
    # gem 'activerecord', '>= 7.0.4'
    # gem 'actionpack', '>= 7.0.4'
    
  • 排查其他潜在冲突

    • webpacker:Rails 7默认使用importmap或jsbundling-rails,若继续用webpacker,建议锁定版本为~> 5.4确保兼容
    • turbolinks:Rails 7推荐用turbo-rails替代,若要保留turbolinks需确认版本兼容性,或考虑迁移到turbo
  • 重新执行安装
    清理缓存后重新安装依赖:

    bundle clean --force
    bundle install
    

内容的提问来源于stack exchange,提问作者cefsdp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 22:55:17