views:

504

answers:

3

The rails books and web pages I've been following have all stuck to very simple projects for the sake of providing complete examples. I'm moving away from the small project app and into a realm of non-browser clients and need to decide where to put code that is shared by all involved parties.

The non-browser client is a script that runs on any machine which can connect to the database. Browser clients write commands into the database, which the script examines and decides what to do. Upon completion, the script then writes its result back. The script is not started by the RoR server, but has access to its directory structure.

Where would be the best place for shared code to live, and how would the RoR loader handle it? The code in question doesn't really belong in a model, otherwise I'd drop it in there and be done with it.

+4  A: 

I answered a similar question at http://stackoverflow.com/questions/285148/where-should-my-non-modelnon-controller-code-live#285152

Hope it's useful :)

Gareth
+3  A: 

I'd put the shared code in the Rails project's /lib directory and consider making it a custom Rake task.

John Topley
I was just going back through some of my old questions and came across this one again and was wondering - what would be the purpose of the rake task?
A: 

It really depends on how much you use this shared code. If you use it everywhere, then throw it in the lib folder (as has already been stated here). If you are only using it in a few places, you might want to consider making a plugin out of it and loading it only in the places that use it. It's nice to only load what you need (one of the reasons I'm loving merb).

Kevin Kaske