【发布时间】:2017-05-18 00:17:42
【问题描述】:
根据rbenv -global,我的红宝石版本是2.3.3
我拥有的 Rails 版本:
*** LOCAL GEMS ***
rails (5.1.1, 5.0.0)
最初,我的目标是用 Spree 创建一个 Rails。像往常一样,我开始了:
rails new spree_app
在Spree README 之后,我将以下宝石添加到我的gemfile:
gem 'spree', '~> 3.2.0'
gem 'spree_auth_devise', '~> 3.2.0.beta'
gem 'spree_gateway', '~> 3.2.0.beta'
然后,当我运行 bundle install 时遇到以下错误:
Bundler could not find compatible versions for gem "rails":
In snapshot (Gemfile.lock):
rails (= 5.1.1)
In Gemfile:
rails (~> 5.1.1)
spree (~> 3.2.0) was resolved to 3.2.0, which depends on
spree_frontend (= 3.2.0) was resolved to 3.2.0, which depends on
canonical-rails (~> 0.1.0) was resolved to 0.1.2, which depends on
rails (< 5.1, >= 4.1)
spree (~> 3.2.0) was resolved to 3.2.0, which depends on
spree_core (= 3.2.0) was resolved to 3.2.0, which depends on
deface (~> 1.0) was resolved to 1.2.0, which depends on
rails (>= 4.1)
spree (~> 3.2.0) was resolved to 3.2.0, which depends on
spree_core (= 3.2.0) was resolved to 3.2.0, which depends on
rails (~> 5.0.0)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
按照建议运行 bundle update 会产生以下结果:
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 5.1.1)
spree (~> 3.2.0) was resolved to 3.2.0, which depends on
spree_core (= 3.2.0) was resolved to 3.2.0, which depends on
rails (~> 5.0.0)
所以在我看来,Spree 依赖于 Rails 5.0.0,而我的 5.1.1 引起了问题。鉴于此,我将gem 'rails', '~> 5.1.1' 更改为gem 'rails', '~> 5.0.0',运行bundle update 和bundle install,一切都在打包程序方面正常工作。
问题是这似乎破坏了我的 rails 应用程序。运行时,任何rails generate 命令或rails s 都会给我以下错误:
/usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x0055a1cd5a36f0> (NoMethodError)
对于我的一生,我不知道这是怎么回事。
我最后的尝试是尝试在 5.0.0 中生成一个新的 Rails 应用程序:
rails _5.0.0_ new spree_app_2
但无论出于何种原因,这似乎没有什么区别。这个应用程序的gemfile 仍然包含gem 'rails', '~> 5.1.1',我遇到了之前遇到的所有相同错误。
看来我要么不知道如何管理不同版本的 Rails,要么没有正确安装 Spree,或者两者兼而有之。任何帮助表示赞赏,谢谢。
更新:部分解决方案
我仍然不知道如何在5.1.1 之外的任何版本中生成 Rails 应用程序,并且简单地更改 gemfile 中的版本仍然对我不起作用。在我看来,还需要一些其他的改变。
我将gemfile 中的rails 版本从5.1.1 切换为5.0.3。使用 5.0.2 查看 Rails 应用程序中的 /config/application.rb 文件,发现它们有不同的设置。
我的看起来有这个:
module AppName
class Application < Rails::Application
config.load_defaults 5.1
end
end
5.0.2 中生成的 rails 应用程序是这样的:
module AppName
class Application < Rails::Application
config.generators do |generate|
generate.assets false
end
end
end
所以我用它换掉了我所拥有的东西,它奏效了!我真的不知道为什么它会起作用,我仍然不知道为什么我可以从一开始就生成一个5.0.3 Rails 应用程序。
【问题讨论】:
标签: ruby-on-rails ruby rubygems spree gemfile