How to Use Gems in Ruby on Rails

preview_player
Показать описание
Can you tell me how to use Gems in Ruby on Rails?

In many regards, Gems are like object oriented programming modules in Java. You simply add them to your code.

RubyGems is the package manager.

You use the gem command to install and manage Gem packages.

But it doesn’t always work.

If you don’t put the gem contacts in your Gem file before running the bundle install, it may error out. You have to specify a gem in the gemfile and use the bundler to install the dependency to get it to run in Rails 3.

How is all of that related to the bundler?

Bundler is used to track and install exact gems and their versions. Bundler ensures the gems you need are present as you remove, install and upgrade them.

That’s like a built in configuration manager. How do you access it?

You start working with bundler with the command bundle install.

That’s like saying to hit the start button to start.

You then specify the dependencies in the gemfile at the project’s root. Then you install all required gems from the sources you specify.

How do you ensure everyone uses the same gems?

Then you need to specify the gem versions to use.

You load the bundled environment in the app using the require rubygems, run bundler setup and then require your specific gems.

How do you run the gems?

You run the executable that comes with the gems with the bundle exec then gem name.

I thought you didn’t always have to run the gem with the execute command.

You could run executables without bundle exec if the executable is already installed on your system, assuming it doesn’t conflict with gems you already have installed.

That would be beautiful.
Рекомендации по теме
Комментарии
Автор

I've had nightmares like this. The nightmares aren't as instructional, but they leave me with the same dreadful feeling.

augustuslxiii