Plugins versus Gems

Rails 2.1 introduced some nifty ways to manage gems that your Rails application depends upon. However, using gems *instead of* plugins seems to a growing practice as well.

I'm just wondering why this is? Installing a plugin means

- plugins are downloaded from a remote source and copied into vendor/ plugins - Rails automatically finds code in vendor/plugins

rake gems:install in Rails 2.1 means:

- gems can downloaded from a remote source and "unpacked" (source copied) into vendor/gems - Rails automatically finds code in vendor/gems

What is the rationale for preferring one over the other?

The main advantage I see of gems is finer-grained control over the version of the gem you will allow your app to use (a non-issue if you unpack anyway).

Thanks, Jeff

softiesonrails.com purpleworkshops.com

I have wondered this very same thing so hopefully someone can provide some insight into it.

I do however believe that a gem is available system-wide, where a plugin is only available to the particular application that it is installed in. Is that correct anyone?

--Cory

That is correct, but is a double-edged sword. For the same reason it's best to "freeze" rails to your app so that you're not dependent on the system-wide Rails gems (unexpected upgrades or downgrades), I think most people will also "freeze" (unpack) their gems into their app as well.

Perhaps the main advantage is to simply have the choice. I can install gems once without replication if many apps use the same gems (like will_paginate, pdf-writer, etc.) if I'm willing to rely on system-wide gems. Or, I can choose to unpack if I wish.

Whereas with plugins, you could easily do the same by symlinking vendor/plugins to a shared directory on your server, but perhaps this wasn't obvious to many people.

Jeff

softiesonrails.com purpleworkshops.com

REST with Rails, Oct 4, 2008, Austin, TX: http://www.purpleworkshops.com/workshops/rest-and-web-services

There is one advantage that I see with gems over plugins: If I'm away from an internet connection working on my application and get to a point that I need to use a gem/plugin it's easier with a gem. I can simply vendor it (or just use it). But, unless I have previously downloaded and stored a plugin somewhere on my local hard drive, I'm stuck.

Not that it's is much different than with a gem I might not have, but I'm saying the likelihood of having a commonly used gem installed is higher than the case for a plugin.

Jeff Cohen wrote:

Also plugins i believe are only for rails, while gems can be used by any ruby application (or framework).