Miles to go …

September 4, 2007

TOTD #6: Difference between Ruby Gem and Rails Plugin

Filed under: web2.0 — arungupta @ 5:58 am

As a newbie to Rails, "Gem" and "Plugin" terminology was slightly confusing to me. Specifically I saw the terms being used interchangeably sometimes. This TOTD highlights the difference between Ruby Gem and Rails Plugin.

Ruby Gem and Plugin are both packaging systems – the main difference is the scope in which they are effective. The common differences are highlighted in the table below.

Topic Ruby Gem Rails Plugin
Definition A Gem is a packaged Ruby application using the packaging system defined by RubyGems. A Rails plugin is a packaged Ruby application that extends the core Rails framework.
Example Has a name (e.g. rake) and a version (e.g. 0.4.16). Rails is also installed as a Gem. Has a name (e.g. Goldspike) and a version (e.g. 1.1.1).
Scope Installed in the Ruby or JRuby installation and is available to all applications run using that interpreter. Installed in a specific Rails app only.
Packaging System Rails gem is installed in jruby-1.0\lib\ruby\gems\1.8\gems\rails-1.2.3 as:

<DIR>        bin
<DIR>        builtin
      68,465 CHANGELOG
<DIR>        configs
<DIR>        dispatches
<DIR>        doc
<DIR>        environments
307          fresh_rakefile
<DIR>        helpers
<DIR>        html
<DIR>        lib
       1,072 MIT-LICENSE
      11,969 Rakefile
       8,001 README

The lib directory contains all the gem source code.

Goldspike plugin is installed in vendor\plugins\rails-integration directory of the application as:

      7,089 build.xml
      1,141 LICENSE.txt
<DIR>       plugins
      6,675 pom.xml
      1,447 README
<DIR>       samples

plugins/goldspike directory consists of

         24 init.rb
         25 install.rb
<DIR>       lib
        549 Rakefile
        536 README
<DIR>       tasks
<DIR>       test

The lib directory contains all the plugin source code.

Management Gems are managed on your computer using the gem command. You can install, remove and query gem packages using the gem command. Plugins can be installed using after creating a Rails application and then invoking the command

ruby script\plugin install [url or name of plugin]

Load Path gem command adds the lib directory of your gem to the load path of Ruby. Rails adds the lib directory of plugin in your application’s load path.
Specific Features  
  • Bundled Rake tasks that get automatically loaded into your Rakefile
  • An installation hook (install.rb)
  • An application initialization hook for the plugin to inject itself (init.rb)
  • ability to bundle additional generators (for the script/generate script)
Publish Format A Gem may be published as Plugin, for example ActiveRecord-JDBC. A Plugin cannot be published as Gem.

Here are some useful entries (with numerous pointers on screencasts, blogs, tips & extensive feature sets) to get you started with JRuby:

Are there any other main differences that I missed ?

Please leave suggestions on other TOTD that you’d like to see. A complete archive is available here.

Technorati: totd rubyonrails rubygem railsplugin netbeans glassfish

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. Ruby-on-Rails Hello World on GlassFish
  2. TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
  3. Rails and Java EE integration – Servlet co-bundled and invoked from Rails
  4. TOTD #24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1
  5. TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows

11 Comments »

  1. I am interested in your showing of
    Ruby Gem and Rails Plugin
    but sorry, I am unable to read the information
    on this site because the calender is shown as
    background and other information as overlay of
    the Rails Plugin information.
    It seems this page is not prgrammed true to
    conventions.
    My browser Firefox 2.006.
    Klaus Ramelow

    Comment by Klaus Ramelow — September 10, 2007 @ 8:11 am

  2. I can view the information fine on 1024 x 768 resolution. What is your resolution ?

    Comment by Arun Gupta — September 12, 2007 @ 6:43 am

  3. great! thanks a lot for this, I’m a Rails and Ruby n00b and this was very helpful

    Comment by ryouji_shiki — November 7, 2007 @ 9:34 am

  4. Great writeup.

    I would make a correction, though. Plugins MAY have a version. Many don’t – all they have it a subversion repo.

    This is one of the main benefits of gems vs. plugins, in my opinion. Gems MUST have a version, which means it is always possible to ensure that you are running a specific version (using the RubyGems ‘gem’ method to put a specific gem version on your load path). You can also use advanced versioning to automatically use a more recent version, if available, or to do fancy things such as using a newer "TINY" or "MINOR" version, but not a newer "MAJOR" version.

    With a plugin, you are dependent on the developer to provide SVN tags to indicate individual versions – but they don’t necessarily have to (and often don’t, because they don’t have to make a new version in order to release, like they do with gems). You also have to manually install the new versions, instead of using flexible versioning to automatically pick up newer versions.

    Also, if you use a tool like my GemInstaller (http://geminstaller.rubyforge.org), you can easily automate the installation and loading of RubyGems with a single simple config file.

    – Chad

    Comment by Chad Woolley — December 8, 2007 @ 1:14 pm

  5. Chad, thanks for the additional tip!

    Comment by Arun Gupta — December 13, 2007 @ 11:38 pm

  6. Hi, this is very helpful, some more that would be good is how do you access gems vs plugins within rails, are they the same, do you need to do a ‘require’ for one and not the other. Also if a package has a gem and a plugin distribution, and you install both of them, who will win? (which will be used by rails?)

    Comment by Joel Nylund — February 28, 2008 @ 2:02 pm

  7. @Klaus: see the Matrix via the Firefox menu View -> Page Style -> No Style.

    Comment by Matt Platte — June 14, 2008 @ 9:46 am

  8. dffsfdfsf

    Comment by sfafsaf — November 3, 2008 @ 9:51 pm

  9. you access gems vs plugins within rails, are they the same, do you need to do a ‘require’ for one and not the other. Also if a package has a gem and a plugin distribution, and you install both of them, who will win?

    Comment by BATTERY — November 27, 2008 @ 5:18 pm

  10. thanks for putting it up

    Comment by anon — May 7, 2009 @ 12:49 pm

  11. Thanks for posting this. Though I haven’t created gems or plugins, I’ve often wondered how they work – especially how plugins initialize (with init.rb).

    Comment by Michael McCracken — April 16, 2010 @ 2:18 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress