【问题标题】:Why does the Rails Composer update Rails when it builds an app?为什么 Rails Composer 在构建应用程序时会更新 Rails?
【发布时间】:2017-01-07 17:11:38
【问题描述】:
# I run these commands:
$ rvm current
ruby-2.3.3@rails500
$ gem list | grep '^rails '
rails (5.0.1, 5.0.0)
$ gem uninstall rails -v 5.0.1
Successfully uninstalled rails-5.0.1
$ gem uninstall railties -v 5.0.1
Successfully uninstalled railties-5.0.1
$ gem list | grep railties
railties (5.0.0)
$ rails -v
Rails 5.0.0
$ rails new . -m \
https://raw.github.com/RailsApps/rails-composer/master/composer.rb
# After I answer all the prompts, a Gemfile is created, which requires
# rails '~> 5.0.1'. After running to completion, Rails Composer leaves
# me with Rails 5.0.1:
$ rails -v
Rails 5.0.1

我没有明确要求 Rails 5.0.1。那我为什么会得到它? 它似乎干扰了 Rails Composer。看 https://github.com/RailsApps/rails-composer/issues/261https://github.com/RailsApps/rails-composer/issues/260

【问题讨论】:

    标签: railsapps


    【解决方案1】:

    您已观察到Rails new 命令的行为。 Rails Composer 是一个 Rails 应用程序模板,搭载在 Rails new 生成器上。 Rails new 命令生成一个简单的默认 Rails 应用程序,然后 Rails Composer 修改它。 Rails new 命令生成的 Gemfile 包含 gem 'rails', '~> 5.0.0'。请注意~> 5.0.0 指定的“悲观版本控制”。这意味着使用任何大于 5.0.0 和小于 5.1 的版本(可以使用任何补丁版本)。当Rails new 生成器运行时,它使用简单的默认Rails 应用程序提供的Gemfile 更新gem,包括Rails gem。因此,Rails 5.0.1 gem 会在 Rails Composer 运行之前安装。

    您可以通过在不使用 Rails Composer 应用程序模板的情况下运行 Rails new 命令来观察此行为。

    myapp/2.4.0@rails500 $ rvm current ruby-2.4.0@rails500 myapp/2.4.0@rails500 $ gem list | grep '^rails ' rails (5.0.0) myapp/2.4.0@rails500 $ rails -v Rails 5.0.0 myapp/2.4.0@rails500 $ rails new . . . . run bundle install . . . Installing rails 5.0.1 . . . myapp/2.4.0@rails500 $ rails -v Rails 5.0.1

    总之,您的问题在于 Rails new 命令,而不是 Rails Composer。

    【讨论】:

    • 非常感谢,丹尼尔!也有一种解决方法。将 'rails new' 启动为 'rails 5.0.0 new' 将在新应用程序中使用 Rails 5.0.0。我用 Rails Composer 试过这个,发现它有效。
    • 对不起。我忘了用反引号来逃避命令。非常感谢,丹尼尔!也有一种解决方法。以'rails _5.0.0_ new' 启动'rails new' 将在新应用程序中使用Rails 5.0.0。我用 Rails Composer 试过这个,发现它有效。
    猜你喜欢
    • 2010-11-04
    • 2013-01-26
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 2022-07-24
    • 2017-07-01
    相关资源
    最近更新 更多