【问题标题】:How does Bundler know what environment to use?Bundler 如何知道使用什么环境?
【发布时间】:2010-12-13 08:10:49
【问题描述】:

这可能是关于 Bundler 的一个非常“新手”的问题,但我想知道 bundle install 如何知道要使用什么环境或如何设置它?或者我什至需要?我的问题是我已经按环境对我的 gem(在 Gemfile 中)进行了分组,现在部署时我只想安装生产 gem。

【问题讨论】:

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


    【解决方案1】:

    application.rb文件的顶部你可以看到

    # If you have a Gemfile, require the gems listed there, including any gems
    # you've limited to :test, :development, or :production.
    Bundler.require(:default, Rails.env) if defined?(Bundler)
    

    当 Rails 启动时,Bundler 会自动加载 :default 组和当前环境的所有依赖项。

    请注意,当您运行 bundle install 时,Bundler 会解析并安装所有环境的依赖项,除非您指定 --without option

    $ bundle install --without staging development test
    

    在生产中,您可能还想添加 --deployment 标志。

    More info about bundle install.

    【讨论】:

      【解决方案2】:

      您可以在 gem 深化声明中使用“组”选项。检查这个 ASCIICast:http://asciicasts.com/episodes/201-bundler

      【讨论】:

        猜你喜欢
        • 2023-03-12
        • 1970-01-01
        • 2017-02-12
        • 2017-04-21
        • 1970-01-01
        • 2018-10-20
        • 2012-09-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多