views:

444

answers:

3

As far as I know, the only difference is in "installation". I've also heard that plugins are somehow harder to update. But would I want to install something as a plugin instead of gem?

+2  A: 

I'd say this question is likely to be debatable to which is the best approach but my thoughts none the less..

The biggest win I would say in using a gem over a plugin if given the option are gem dependencies.

Rails plugins don't handle dependencies, so if you install a plugin that relies on other plugins/gems, you have the inconvenience of installing these additionally. Where as installing a gem can at the same time pull in any dependencies required for it to run. Take the cucumber gem for example:

'sudo gem install cucumber' will install the cucumber gem, but will also install its dependencies such as the webrat gem.

This may not seem like a big thing, but when you are dealing with multiple environments (development, staging, production etc.) you are more prone to encounter dependency issues.

The only scenarios where you are likely to want a plugin over a gem is when you conveniently want access to the plugin code. One case may be if the plugin is infact a Rails engine and you need to quickly dive into the code and see what class/view you want to override. Another case may be if you have forked a plugin such as active_merchant, and have it setup as a git submodule in vendor/plugins. Committing and pushing changes upstream tends to be alot more convenient in this scenario.

As for one being harder to update over the over, gems have rubygems to manage them which is straight-forward enough, and if you happen to be using git then submoduled plugins are a doddle to update:

# installing a plugin as a git submodule
git submodule add git://path_to_plugin_git_repo.git vendor/plugins/plugin_name

# updating said git submodule
cd vendor/plugins/plugin_name
git remote update
git rebase origin/master
cd ../../..
git add .
git commit -m "update plugin_name to latest master."

or the equivalent for SVN externals

Installing something as a gem or a plugin however shouldn't affect the functionality of the code as they are just two different ways of packaging code up, in the end it comes down to what you find more convenient to use I guess. Personally I find gems much easier to maintain unless I'm likely to be getting stuck into the code, then a submoduled plugin is more to my favour as it will show up in project tree in my editor.

Mark Connell
I just tried this and it needs to begit submodule add git://path_to_plugin_git_repo.git vendor/plugins/plugin_name
nasmorn
Aha, thanks for spotting that, updated answer to reflect
Mark Connell
+2  A: 

Gems:

  • Can handle dependencies
  • Can be installed system-wide
  • Can also be vendored (in vendor/gems)
  • Has a concept of versions, can easily specify which version you want

Plugins:

  • Very easy to publish for authors

Apparently, the only advantage for plugins is a powerful advantage, since plugins are still very common. I tend to agree. Publishing a plugin = creating a github repository. Publishing a gem requires you to create a gemspec, and perhaps even meddle with The Gem Beast (rubyforge), which both are PITAs.

August Lilleaas
Well, `gemcutter` now, which is quite a bit simpler.
Bob Aman
A: 

I always use gems if possible because I feel it's much easier to keep them update.

However, one major annoyance is that gems can't provide rake tasks but plugins can. This will often result in frustration when, for example, you try to execute rake paperclip:refresh only to be informed that the task doesn't exist.

The solution is to copy the gem's rake tasks to your apps tasks directory.

hopeless