# Drb vs. rails autoloading

**URL:** <https://www.ruby-forum.com/t/drb-vs-rails-autoloading/90661>\
**Category:** Rails\
**Created:** [March 30, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/drb-vs-rails-autoloading/90661 "2007-03-30T19:40:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@tobias](https://www.ruby-forum.com/u/tobias)\
**Post date:** [March 30, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/drb-vs-rails-autoloading/90661/1 "2007-03-30T19:40:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tobias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@tobias](https://www.ruby-forum.com/u/tobias)\
**Post date:** [April 1, 2007, 7:52pm UTC](https://www.ruby-forum.com/t/drb-vs-rails-autoloading/90661/2 "2007-04-01T19:52:14Z")

</div>

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](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
