What is the difference between plugins and gems? What are the different uses of each? Where and why would you use one over the other?
- Gem is a packaged ruby application using the packaging system defined by RubyGems.
Rails itself is a Gem.
Rails gem is installed in jruby-1.0\lib\ruby\gems\1.8\gems\rails-1.2.3 as:
The lib directory contains all the gem source code.
We can install,upgrade and query the gem version.If one uses a tool like my GemInstaller, one can easily automate the installation and loading of RubyGems with a single simple config file.
- Gem installed for Ruby interpreter can be used system-wide by that interpreter.
- Gem may be published as a plugin.
- Can also be vendored in vendor/gems.
- Plugin is an extension of Rails Framework.
- Can not be upgraded by using a command. To upgrade one have to uninstall and then install upgraded version.
- Has to be hooked into rails application. (has to have init.rb)
- Have an install.rb file.
- Plugin cannot be published as a Gem.
- Can only be used application wide.
Goldspike plugin is installed in vendor\plugins\rails-integration directory of the application as:
plugins/goldspike directory consists of
The lib directory contains all the plugin source code.
Gem vs Plugins
- Rails had a way of loading plugins from the vendor/plugins/ directory. This will most likely deprecate as Rails has added support for bundling gems with the project in the vendor/gems/ directory. The gem versions of rspec are the ones that are intended for everyday use. One should go with those unless you are supporting a Rails application in the 1.2.x family or earlier.
- It often becomes quicker to check-in and check-out of a repository using Gems as you are not including the library in your actual application. There are often lesser problems using Plugins related to incompatibility arising concerning software versions among the distributed team.
- General rule of thumb is to make Rails-specific functionality a plugin while making more general Ruby libraries into gems.