Setting Up Your Application to Use Bundler


Bundler makes sure that Ruby can find all of the gems in the Gemfile (and all of their dependencies).

For another kind of application (such as a Sinatra application/Ruby app), you will need to set up bundler before trying to require any gems. At the top of the first file that your application loads , put the following code:

require "rubygems"
require "bundler/setup"

This will automatically discover your Gemfile, and make all of the gems in your Gemfile available to Ruby (in technical terms, it puts the gems “on the load path”). You can think of it as an adding some extra powers to require "rubygems".

Now that your code is available to Ruby, you can require the gems that you need. For instance, you can require "nokogiri". If you have a lot of dependencies, you might want to say “require all of the gems in my Gemfile“. To do this, put the following code immediately following require "bundler/setup":
Bundler.require(:default)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s