【问题标题】:Various difficulties creating Rails apps in different versions and installing Spree创建不同版本的 Rails 应用程序和安装 Spree 的各种困难
【发布时间】: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', '~&gt; 5.1.1' 更改为gem 'rails', '~&gt; 5.0.0',运行bundle updatebundle 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', '~&gt; 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


    【解决方案1】:

    我绝不是 Spree 专家,但从外观上看,5.1.1 与 Spree 不兼容。

    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)

    在您的Gemfile 中,继续将gem 'rails', '5.0.3' 放在顶部(替换任何其他rails gem),然后在rm Gemfile.lock 后面加上bundle

    应该做的伎俩。

    【讨论】:

    • 好吧,这消除了 gem 依赖项的问题,但就像我最初所做的一样,每当我尝试运行诸如 rails s 或 @ 之类的 rails 命令时,我都会遇到相同的 undefined method 'load_defaults' for #&lt;Rails::Application::Configuration:0x0055e0414ccdf0&gt; 错误987654330@.
    • gem install rails -v 5.0.3rails _5.0.3_ new application_name 怎么样?
    • reporting all-systems-go over here with 2.3.1;快速尝试 2.3.3!
    • ... 但首先我要安装 2.3.3;快乐!
    • 好的,我已经这样做了,但似乎没有什么不同。我的gemfile 仍然包含gem 'rails', '~&gt; 5.1.1' 并在添加Spree gems 后运行bundle install 给我同样的依赖投诉。我不应该在我的gemfile 中看到gem 'rails', '~&gt; 5.0.3' 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多