Controllers, Models, Libraries -- Better Ideas Welcome

Hi,

So I’ve been looking into RoR for a couple of weeks, on and off.
Primarily at some of the more sophisticated bits and pieces. Anyway,
today I thought that instead of poking about I’d actually do
something. None of the projects I’m immediately interested in would
be helped by using ActiveRecord (I wrote xampl, so if you know what
that is you’ll know what I mean). However, the rest of Rails is a
different story.

So I made a simple controller with no model. No problem. Moved it
down one into a subdirectory of app/controllers wrapping it up in a
module as seems to be necessary. No problem. Wrote a simple class and
stuck it under the lib directory and called it from the controller.
It starts to get interesting. The first time works. The second time
doesn’t because the class in the lib directory isn’t found
(unrecognised constant or something similar). The controller is re-
loaded every time the server is hit, but the file in the lib isn’t
(only loaded once). So how does anything work? Must be the model.
Wrote a trivial model that doesn’t do anything other than require the
file under lib. Referred to the model in the controller I wrote,
instantiated a model class in the controller. It now works (at least
several times). The model is also loaded with each request. What is
the difference between how a controller loads something and a model?

Why?

Is this reliable (will this keep working in future releases)?

Surely there is a better way? Environments somehow (couldn’t get
these to work)?

What are the rules for classes that stay in memory?

Any suggestions or ideas are appreciated.

Thanks,
Bob


Bob H. – blogs at <http://www.recursive.ca/
hutch/>
Recursive Design Inc. – http://www.recursive.ca/
Raconteur – http://www.raconteur.info/
xampl for Ruby – http://rubyforge.org/projects/xampl/