# Empty classes not found

**URL:** <https://www.ruby-forum.com/t/empty-classes-not-found/124484>\
**Category:** Rails\
**Created:** [December 29, 2007, 4:00am UTC](https://www.ruby-forum.com/t/empty-classes-not-found/124484 "2007-12-29T04:00:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [December 29, 2007, 4:00am UTC](https://www.ruby-forum.com/t/empty-classes-not-found/124484/1 "2007-12-29T04:00:15Z")

</div>

I have a module called Retain. That module has pieces in  
app/controller/retain, app/model/retain, and lib/retain. If I have to,  
I can rename them but, for now, that is what I have.

In lib/retain I have a file called exceptions where I define my  
exceptions like:

module Retain  
class RetainEerror \< StandardError  
end

class FooError \< RetainError  
end  
…  
end

I have an explicit “require ‘retian/exception’” in one of my  
controllers. The very first run through the code, it finds FooError,  
etc. The next time (like if I hit refresh), it does not. FooError  
becomes undefined.

This is in development mode and I have class caching turned off:

config.cache\_classes = false

Is the fact that I have the Retain module scattered all over the  
problem? If not, can anyone suggest what the problem might be?

Thank you,  
pedz

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [December 29, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/empty-classes-not-found/124484/2 "2007-12-29T21:18:15Z")

</div>

On Dec 29, 2007 2:00 PM, Perry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> This is in development mode and I have class caching turned off:  
> config.cache\_classes = false

> Is the fact that I have the Retain module scattered all over the  
> problem? If not, can anyone suggest what the problem might be?

Probably not the problem with scattering the file all over the place.  
More likely to do with Rails’ dynamic reloading of the files on each  
refresh in development mode.

What happens if you turn on class caching or run in production mode?

If this works, you might want to move the require ‘foo’ into the  
application\_controller as a more central require location or even  
better, put it in as an initializer file in config/initializers if you  
are on Rails 2.0 or in an environment.rb file if you are not.

Regards

Mikel

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [December 30, 2007, 12:27am UTC](https://www.ruby-forum.com/t/empty-classes-not-found/124484/3 "2007-12-30T00:27:11Z")

</div>

I turned on the class caching and that solved the problem. I then  
turned it back off and rearranged the require and put the require in  
config/initializers and that is working too.

Thanks for your help,  
pedz
