添加 gem "font-awesome-rails" 后的捆绑包安装问题

Bundle Install Issues after adding gem "font-awesome-rails"

我正在使用 Udemy 的教程来创建 Web 应用程序,并且我正在使用 cloud9 IDE。在添加 font-awesome 之前一切正常。在添加 font-awesome gem 后尝试捆绑安装时,出现以下错误:

Bundler could not find compatible versions for gem "activemodel":
  In Gemfile:
    rails (~> 5.2.0) was resolved to 5.2.1.rc1, which depends on
      activemodel (= 5.2.1.rc1)

    web-console (>= 3.3.0) was resolved to 3.3.0, which depends on
      activemodel (>= 4.2)

Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    jbuilder (~> 2.5) was resolved to 2.8.0, which depends on
      activesupport (>= 4.2.0)

    rails (~> 5.2.0) was resolved to 5.2.1.rc1, which depends on
      activesupport (= 5.2.1.rc1)

    spring was resolved to 2.0.2, which depends on
      activesupport (>= 4.2)

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

    font-awesome-rails (= 4.2.0) was resolved to 4.2.0.0, which depends on
      railties (< 5.0, >= 3.2)

    jquery-rails was resolved to 4.3.3, which depends on
      railties (>= 4.2.0)

    rails (~> 5.2.0) was resolved to 5.2.1.rc1, which depends on
      railties (= 5.2.1.rc1)

    sass-rails (~> 5.0) was resolved to 5.0.7, which depends on
      railties (< 6, >= 4.0.0)

    web-console (>= 3.3.0) was resolved to 3.3.0, which depends on
      railties (>= 4.2)

这是我当前的 gem 个文件:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.4.1'

gem 'rails', '~> 5.2.0'

gem 'sqlite3', group: [:development, :test]


gem 'bootstrap-sass', '~> 3.3.7'

gem "font-awesome-rails", '4.2.0'


gem 'jquery-rails'

group :production do
  gem 'pg'
  gem 'rails_12factor'

end


gem 'puma', '~> 3.11'

gem 'sass-rails', '~> 5.0'

gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.2'

gem 'turbolinks', '~> 5'

gem 'jbuilder', '~> 2.5'

gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console', '>= 3.3.0'

  gem 'listen', '>= 3.0.5', '< 3.2'

  gem 'spring'

  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do

  gem 'capybara', '>= 2.15', '< 4.0'

  gem 'selenium-webdriver'

  gem 'chromedriver-helper'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

所以在搜索类似问题后,我尝试删除我的 gemlock 文件和 运行ning 捆绑包更新,但没有成功。尝试 运行 我的服务器只是给我一个错误,需要先安装 'font-awesome-rails' 包。

对于格式化,我也深表歉意,这是我的第一个问题。感谢任何帮助。

问题是以下约束:

gem "font-awesome-rails", '4.2.0'

如以下部分所述:

font-awesome-rails (= 4.2.0) was resolved to 4.2.0.0, which depends on
  railties (< 5.0, >= 3.2)

font-awesome-rails 的 4.2 版本要求 Rails < 5.0,但是你使用的是 Rails 5.2.0,所以 bundler 不知道该做什么(你不能给定 gem 的几个版本)。

解决方案是给我们一个无版本的 gem 声明:

gem "font-awesome-rails"

不用担心 gem 的版本,bundler 足够聪明,可以为您提供最新的兼容版本!

注意:您也可以使用 the pessimistic operator,如:

gem "font-awesome-rails", '~> 4.2'