views:

123

answers:

2

I have features I would like to be portable between my own Rails applications.

I wonder if I should create a gem or a plugin for each feature I want to be portable (sharable).

They are just for Rails (for now) because they include css, html, js and image files.

But I have been wondering, the things provided with plugins could be provided with gems too but not the opposite? So maybe it's better to learn how to create gems, because then you I don't have to learn how to create both gems and plugins? And gems seem to be more popular these days.

But then, from what I can understand one gem is shared between all rails app in the OS. So that means I can not customize it for each Rails app right? In that case, maybe creating a plugin is better cause it should be allowed to customize (editing css, js etc) each feature and to have it stored inside the Rails app itself and not in the OS level.

Some advices would be appreciated!

UPDATE:

So gem works great with css, html, js and image files? In a plugin I think you can have a MVC, your own models, views and controllers. Quoted from Rails guides "Storing models, views, controllers, helpers and even other plugins in your plugins". Is this possible too in a gem? Eg. I want to add a extension that gives me a nice Shopping cart (with own migrations, mvc, asset files) that will be hooked into the current Rails app. Is this possible as gem or only as plugin?

+1  A: 

You're right that gems offer a little more than plugins. Versioning and dependencies on other gems being the main ones for me.

One gem needn't be shared across everything using ruby. You can install multiple versions of a single gem and specify in your environment.rb that a gem requires a specific version. E.g.

config.gem 'my-gem', :version => '1.2.3'

Also you can freeze gems into your rails application so that you know you are working with a specific version.

You might want to look at the jeweler gem which makes creating your own gems easier.

UPDATE

To include CSS, javascript etc I think you'll need to make an Rails engine which can then be bundled as a plugin or a gem. I've not done this but there's some coverage here and here.

Shadwell
That link to the jeweler gem appears to be broken:http://github.com/technicalpickles/jeweler
Zachary
Please see my updated post.
never_had_a_name
I've fixed the jeweler link. Cheers.
Shadwell
+1  A: 

The push with Rails 3 seems to be towards gems and away from plugins as a lot of support has been added to make gems work as well or better than plugins ever did. A well constructed gem is a great thing to have and share between different applications, and also reduces the amount of testing you will have to do since you can test the gem thoroughly before integration.

For extensions to Rails that use CSS, HTML and other assets, it might be that you need to build an engine to bundle this all up and allow it to fit neatly into an application.

tadman
"you need to build an engine to bundle this all up". What do you mean by engine? You mean Rails engines (aka a rails app inside a rails app) that you could build with Engineer?
never_had_a_name
That sort of thing, yes. There's a lot of ways to construct them, as there is with gems. Here's a site that has some documentation and examples: http://rails-engines.org/
tadman