【问题标题】:How to use conditionals in Gemfile如何在 Gemfile 中使用条件
【发布时间】:2011-03-16 09:49:08
【问题描述】:

我的 Gemfile 中有这些组:

group :development, :test do
   gem 'sqlite3'
end
group :production do
  gem 'mysql'
end

开发机没有安装MySQL,所以我只在生产组中列出了MySQL。但是当我尝试在开发机器上运行 Rails 时,我得到了这个:

$> RAILS_ENV=development ./script/rails 
Could not find gem 'mysql (>= 0, runtime)' in any of the gem sources listed in your Gemfile.

显然我可以通过安装 MySQL 来解决这个问题,但我想知道正确的解决方案,而不是安装不需要的软件。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 rubygems


    【解决方案1】:

    您确实需要安装 gem。 Bundler(Rails 的底层 gem 管理器)需要它,因此您可以解决开发中潜在的依赖冲突,而不是在投入生产时发现您有 gem 冲突。 Yehuda(Bundler 的构建者)写了一篇关于它的博客文章,请查看标题为“一致性”的部分。

    http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

    【讨论】:

      【解决方案2】:

      您是否在更改 Gemfile 后重新运行“捆绑安装”?

      【讨论】:

        【解决方案3】:

        只需运行bundle install --without production

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-01-16
          • 2014-03-29
          • 1970-01-01
          • 2016-03-08
          • 2012-08-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多