Chris Taggart wrote:
Perry Smith wrote:
I want to have a module that I mixin to more than one model.
What would be the most "rails like" way to do this?
I put it in a file (my_mixin_module.rb) in /lib and then include it in
each model that needs it:
class SomeModel < AR::B
Thanks. I was wondering if I need to add a require line at the top.
I'll try it without and see what happens. I'm still not 100% clear of
all the load magic in Rails.
I believe you do have to require the file first, if it's in lib. At
least, I hope so, since automatically loading everything in lib would
be a bit over-eager.
Are you sure? I don't require mine, and it's loaded automatically. Also
there's this in the Rails API:
Application specific libraries. Basically, any kind of custom code that doesn't
belong under controllers, models, or helpers. This directory is in the load path.
Of course, I could be wrong.
lib is definitely in the load path, but that means (or is supposed to
mean) that it's in the $LOAD_PATH array (a.k.a. $:). If everything in
the load path were pre-loaded, Ruby programs would take a long time to
I'm definitely getting an error when I don't require my little test
lib file, and not when I do, with Rails 1.2.3. Which version are you