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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.