Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Using Bundler With Rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 291
    Comment on it

    Bundler is a default gem manager attached with Rails 3 in order to maintain list of gems being used in the project. Although we are talking about bundler here with respect to rails we can use it independently with Ruby too without any dependency on any framework like Rails.
    For using bundle with rails install the gem required for it similarly to other gem we need to install :

    $ gem install bundler

    Create a file of name Gemfile in the root of your app if it is not present over there already. Now add list of all the gems that are required for your project in the Gemfile like

    gem 'httparty' gem 'mocha'

    Once the required Gemfile is ready run the following command bundle install which install the gems mentioned in your Gemfile. Once bundler gets run successfully a new file know as Gemfile.lock is generated which keep record of all the gems being used in the project with the exact version of gem installed.

    There are 2 commands that can be run with respect to bundler is INSTALL or UPDATE

    1) bundle install handles changes to the Gemfile

    2) bundle update upgrades gems that are already managed by Bundler

    If you want to remove particular gem just remove it from a Gemfile and run bundle install but it must be taken care of that this will only remove gem from the project if you want to remove gem completely from your machine it has to be done manually.

    Below is the list of rules that you must take care of while using bundler :

    1) Always use bundle install

    2) If you need to upgrade a dependency that Bundler is already managing, use bundle update .

    3) Don't run bundle update unless you want all of your gems to be upgraded.

    While making a Gemfile you can also take care of following point i.e gems in a Gemfile can be grouped according to development mode i.e production,staging,development,testing.

    group :development, :test do
        gem "rspec-rails"
        gem "factory_girl_rails"
        gem "guard-rspec"

    This approach help a developer such that only gems that are required for a particular development mode are installed like a developer wants to use sqllite for development and mysql for production. Depending on the environment we can mention gem that need to installed and used thus helping developer not to install unneeded gems.

    According to the Bundler website,

    "Bundler manages an application's dependencies through its entire life across many machines systematically and repeatably."

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: