views:

303

answers:

3

Typically I create a plugin when I have a module that I know I'm going to need over again in my other projects, however, they could also be packaged as gems.

When should I be building a gem over creating a plugin? Is there any criteria for making the call?

+8  A: 

Plugins are becoming obsolete now that you can manage gems via the "config.gem" statement in environment.rb. Gems are available system-wide (not just in one app), and are versioned unlike plugins.

I've converted all of my plugins to gems recently. Easy to do and well worth it.

Matt Darby
"Easy to do" link changed to http://mbleigh.com/2008/06/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins.html
cpm
+1  A: 

Rails seems to be moving towards the gem direction. I have converted most of my plugins to gems now. Gems are easier to manage and fit better in the Ruby eco-system. Why do we need two separate systems anyway?

There is still a problem with gems however: it is not possible to add rake tasks to a Rails application from a gem. Probably the same holds for generators, although I'm not sure. If you use these in your plugin, migrating to a gem is not yet possible. Hopefully this gets fixed soon.

wvb
+1  A: 

you can add generators to rails via gems. it's actually pretty easy, you can just add a rails_generators directory to your gem. (i think other directory names will work - i'm not sure what rails searches for). example: http://github.com/remi/rackbox/tree/a21c21667c68d5fd51357e28f0742171e9161e9b/rails_generators

as for adding rake tasks ... i have yet to figure out howto do that :/

for now, i'm having my generators add require 'myproject/rails/tasks' (or something) to the project's Rakefile as a way to add rake tasks to rails from a gem.

a lot of gems ask you to 'bootstrap' them into your rails project, eg. sudo gem install cucumber cd rails_app ./script/generate cucumber # bootstrap cucumber into your app