Best practice for sharing code between rails apps

Is there a writeup about how to structrure your rails applications so
that you can share models, gems, libraries, helpers, and controllers
between them. It would be especially helpful if the discussion
involved how to structure your codebase in version control and how to
manage deployement.

Well, just use subversion for all your apps, then use svn:externals
to share pieces of them with each other. How’s that for a write-up? :slight_smile:


Benjamin C.
http://www.bencurtis.com/
http://www.tesly.com/ – Collaborative test case management
http://www.agilewebdevelopment.com/ – Resources for the Rails community

Well, just use subversion for all your apps, then use svn:externals to share
pieces of them with each other. How’s that for a write-up? :slight_smile:

How would that work exactly? Let’s say I have a model, or a fragment I
want to share amongst different ror apps. I presume I check these
things into their own repos and then “attach” them to my application.
Can I just specify one file or five files as an external or does it
have to be an entire directory. If the latter how do I make sure ror
sees them?

You can only specify directories as externals. So, how you can get
at them depends on what you want to share. If it’s a set of models,
you can attach them as a subdirectory of lib and require it from
there. If it’s a set of views you can attach them to app/views.

These methods are not as convenient as plugins or engines, though.
In fact, this is the best use-case for engines – sharing common
functionality among a number of internal applications. Generally
speaking, you’ll have an easier time of it if you can package up the
functionality you want to share into a plugin or engine and then
install the plugin/engine via svn externals.


Benjamin C.
http://www.bencurtis.com/
http://www.tesly.com/ – Collaborative test case management
http://www.agilewebdevelopment.com/ – Resources for the Rails community

We had a similar problem. So we put all our core business logic into a
set
of shared models, bindled them as a plugin, and distribute them that way
between the applications that share them. This seems to be a little
cleaner
then svn:externals when you want to share some models but not all of
them.

There’s a discussion of this in Rails Recipes, if you can get a copy.
But
making a basic plugin is dead simple:

./script/generate plugin my_plugin_name

will build the plugin structure in vendor/plugins. Then just dump all
your
models into the lib directory. Everything there will be included
automagically by your app.

HTH,
Jeff

will build the plugin structure in vendor/plugins. Then just dump all your
models into the lib directory. Everything there will be included
automagically by your app.

Thank you for the tip. I was under the impression that there would be
some performance problems with plugins but I will try it out and see
for myself.

I thought of one other way which is to use REST or Web services. Run
one rails app that contains the shared functionality and interact with
it via web services from your other rails apps. That might be slower
still but it would certainly work and it would keep things pretty well
separated.

Is there a message que or some sort of a corba like interop service
for ruby? Hopefully one that’s much simpler.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs