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?
Gems:
vendor/gems
)Plugins:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With