There’s been some discussion about this before but I think I have a
I am trying to use modules with models to avoid naming conflicts while
connecting to more than one database.
Everything seems to be working ok in that we have:
- Model definitions in models/namespace/model.rb
- Controllers accessing models by Namespace::Model
- Controllers loading models using « model ‘namespace/model’ »
The only problem I am having is callbacks like before_create,
after_create, etc seem to get called multiple times. For example…
class B < ActiveRecord::Base
def log_create puts '>>> Creating...' end
And then do A::B.create, I get multiple “>>> Creating…” messages,
but only one object in my table.
I am guessing because, in development, require_dependency loads the
file multiple times and the module mess things up somehow - my
callbacks keep piling on top of one another.