Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between gems and plugins?

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?

like image 700
Mohit Jain Avatar asked Aug 16 '10 17:08

Mohit Jain


People also ask

What is a plugin in Ruby on Rails?

A Rails plugin is either an extension or a modification of the core framework. Plugins provide: A way for developers to share bleeding-edge ideas without hurting the stable code base. A segmented architecture so that units of code can be fixed or updated on their own release schedule.

What is a gem in ruby?

The software package is called a “gem” which contains a packaged Ruby application or library. Gems can be used to extend or modify functionality in Ruby applications. Commonly they're used to distribute reusable functionality that is shared with other Rubyists for use in their applications and libraries.


3 Answers

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.

like image 112
Chris Johnston Avatar answered Nov 03 '22 00:11

Chris Johnston


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.

like image 33
dylanfm Avatar answered Nov 03 '22 02:11

dylanfm


When you install a plugin in a project it can be used only in the respective project. But if u install a gem, it can be used by every project. This is the main difference of Gem & Plugins.

like image 42
Arun Avatar answered Nov 03 '22 01:11

Arun