Saturday, 2 February 2013

How to install gems group specific in your rails application

In Ruby on Rails application Gemfile, while you defining gems we can make that gem in a particular group. For example some gems needs to be loaded only on test environment so on that time we can mention those kind of gems into one specified groups. so your gemfile should like this

gem 'aws-s3'
gem 'paperclip'
group :test do
  gem 'rspec'
  gem 'waitr'
  gem 'faker'

If you are planning to define just one gem into a particular group only you can use without blocks like this

gem 'rest-client', :group => :development
gem 'cucuber-rails', :groups => [:development,:test]  (cucuber-rails gems comes under both group)

Similarly you can make it :development,:default(group name) or give a meaningful names whatever you want as group name.

Finally you have to tell while running the "bundle install" command just ignore what are the groups to be ignored using --without.

bundle install --without development
bundle install --without development test (ignore both groups and install others)
The above command ignore whatever gems we mentioned in the development group. So it will install rest of the default group(if you are not mention any group  those gems comes under defaults group)gems and test group gems.

bundle install --without development (ignore development group gems)
bundle install (still bundle remembers --without development so result is still ignore development groups it will not install all gems)

bundle install --without nothing (just clearing cache, now all the gems to be loaded into the ruby loadpath) 

1 comment :

  1. Nice post ! Thanks for sharing valuable information with us. Keep sharing..Ruby on Rails Online Training