Erik
Erik

Reputation: 201

How does Bundler know what environment to use?

Here's probably a very "newbieish" question on Bundler, but I'm wondering how bundle install knows what environment to use or how to set it? Or do I even need to? My problem is that I've grouped my gems (in Gemfile) by environments and when deploying now I only want production gems to be installed.

Upvotes: 20

Views: 10161

Answers (2)

Simone Carletti
Simone Carletti

Reputation: 176362

At the top of the application.rb file you can see

# 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)

When Rails is booted, Bundler automatically loads all the dependencies for the :default group and current environment.

Please note that when you run bundle install, Bundler resolves and install dependencies for all the environments, unless you specify a --without option

$ bundle install --without staging development test

In production, you might also want to add the --deployment flag.

More info about bundle install.

Upvotes: 30

pantulis
pantulis

Reputation: 1705

You can use the "group" option in the gem deependency declaration. Check this ASCIICast: http://asciicasts.com/episodes/201-bundler

Upvotes: 0

Related Questions