Drb vs. rails autoloading


#1

Hi!

When accessing a drb server from within a Rails application, where the
drb server returns an instance of a class that is available in
app/models/, drb/Rails does not require/load the model file. Currently
I need to explicitly require the model file in my controller and/or view
in order to make the model class available to drb. It seems the way drb
requests a class does not work with the way Rails implements the
autoloading.

Is there an easy solution besides simply requiring all models by
default? I don’t want drb to return proxy objects and I don’t want to
use backgroundrb either.

bye,

Tobias


#2

Tobi wrote:

in order to make the model class available to drb. It seems the way drb
requests a class does not work with the way Rails implements the
autoloading.

It seems, Marshal.load() does not trigger const_missing(). I’ve finally
decided to make a small change to drb:

http://pastie.caboo.se/50958

It simply catches the ArgumentException raised by Marshal.load, calls
DRb.auto_require() and retries the unmarshalling. This way in my client
and server code I simply can do something like:

def DRb.auto_require(name)
begin
require(File.dirname(FILE) + ‘/…/app/models/’ +
Inflector.underscore(name))
return true
rescue LoadError
return false
end
end

Tobias