Understanding Gemfile Dependencies

Jan 24, 2012 by     No Comments    Posted under: Learning Rails

I really struggled with this while learning Rails. In the Gemfile, I thought you could have groupings of Gems that would only be installed for a particular environment, like:

group :production do
gem 'execjs'
gem 'mysql'
end

And, you can–but not in the way I thought. What I thought was that if my environment was set to something other than “production,” then those Gems wouldn’t load. But that’s not the case without a little extra coaxing from bundler.

To ignore those gems, when I bundle, I need to add the switch --without production, like

bundle install --without production

Obviously you’d want to change production to whatever group you wanted bundler to skip. Doing this stores a flag in your APP_ROOT/.bundle/config file, and then subsequent bundles won’t include gems within the production group. That’s how you get groupings of Gems to be ignored in your Gemfile. To read more, check out http://gembundler.com/rationale.html.

Got anything to say? Go ahead and leave a comment!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">