views:

71

answers:

4

This may be a very lame question, but still I am confused when should I use a gem and when should I should use a plugin in my project.

What's the basic difference between them?

A: 

Gems are distributed by rubygems, which is the official ruby library package manager. Plugins is a (probably hacky) way for rails plugins. I recommend you using gems whenever possible, due to dependency resolution. Rails3 ecurages that by packing with Bundler.

Tass
+4  A: 

The basic difference is a gem is something that needs to be installed on the system running your Rails application, whereas a plugin is deployed along with your application. More specifically, plugins live in vendor/plugins whereas gems need to be install using rake gem install gem_name.

As for when to use each, gems tend to be easier to keep up to date, but more specifically, some gems use native C code and are compiled specifically for a given operating system (such as Nokogiri). These need to be installed as gems as they will not work when moved to another system. Whereas some things like acts_as_commentable use straight ruby code and can be moved from system to system.

Chris Johnston
A: 

I use gems whenever a gem works as I wanted to and plugins when I want to do a custom change for a specific rails application and not affect all of my system.

JohnDel
A: 

From RailsGuides:

A Rails plugin is either an extension or a modification of the core framework.

From Rubygems.org:

A gem is a packaged Ruby application or library.

So, the biggest difference between the 2 is that Rails plugins are specifically made for use within Ruby on Rails applications, whereas gems aren't.

For example, let's look at Geokit.

The gem (geokit-gem) provides the fundamental location-based operations.

The Rails plugin (geokit-rails) mixes location finders into ActiveRecord.

Here you can see that the gem provides the core of Geokit. This gem can be used anywhere, not just a Rails app. The plugin provides additional features for those who are using geokit within a Rails app. In this case, using the plugin as well as the gem is optional.

dylanfm