Forum: Ruby on Rails drb vs. rails autoloading

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tobias G. (Guest)
on 2007-03-30 21:40
(Received via mailing list)
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
Tobias G. (Guest)
on 2007-04-01 21:52
(Received via mailing list)
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
This topic is locked and can not be replied to.