# Maddening library loading problem

**URL:** <https://www.ruby-forum.com/t/maddening-library-loading-problem/54818>\
**Category:** Rails\
**Created:** [March 14, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818 "2006-03-14T17:07:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [March 14, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818/1 "2006-03-14T17:07:04Z")

</div>

Hi everyone.  
I recently wrote a nice module that I want to use in my rails app. It  
consists of a few files in a directory that I have places in the lib  
directory. It looks like this:  
/lib/KMLTools/foo.rb, bar.rb, baz.rb

Some of these files load each other and I finally got those to work by  
using the File.dirname( **FILE** ) trick. When I simply require the file  
into my controller, everything is fine, but as soon as i try to create  
a new instance of the class i wrote using this code:

d = KMLTools::Document.new()

I get the following error:  
NameError in File#save  
uninitialized constant KMLTools  
This error occured while loading the following files:  
kml\_tools.rb

Now, there is no file kml\_tools.rb, and i am not sure where rails is  
getting this file name.  
I know i should probably make a gem out of the library i wrote, but I  
am not sure if dreamhost lets you install gems.

Does anyone have any suggestions or fixes I could use?  
I’ve been trying to figure this out since yesterday and I am really  
stymied, any help would be greatly appreciated

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [March 14, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818/2 "2006-03-14T17:10:37Z")

</div>

> Now, there is no file kml\_tools.rb, and i am not sure where rails is  
> getting this file name.

I’m guessing(!) there’s an implict aasumption somehere that each module  
will have a single rb file that loads all the others. Therefore  
KMLTools will have a kml\_tools.rb which requires all the other bits and  
pieces.

As for why rails is trying to load that, I’m not sure…

Alan

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [March 14, 2006, 9:06pm UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818/3 "2006-03-14T21:06:36Z")

</div>

On Mar 14, 2006, at 8:10 AM, Alan F. wrote:

> As for why rails is trying to load that, I’m not sure…
> 
> Alan

```
The way rails autoloads classes these days is with const_missing.

```

Which is sort of like method\_missing but for constants. So they first  
time rails sees KMLTools it looks for a file called kml\_tools.rb in  
all of the defined load paths.

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [March 23, 2006, 12:26am UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818/4 "2006-03-23T00:26:13Z")

</div>

Chris,

Did you ever find a solution for this?

I am having the exact same problem but with a RubyGem!!! (see:  
[RubyGem loading into a controller (High quality question) - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/59088))

I will be sure to pass on any info. that I get about my problem.

Thanks,  
Wes G.

Ezra Z. wrote:

> On Mar 14, 2006, at 8:10 AM, Alan F. wrote:
> 
> > As for why rails is trying to load that, I’m not sure…
> > 
> > Alan
> 
> The way rails autoloads classes these days is with const\_missing.  
> Which is sort of like method\_missing but for constants. So they first  
> time rails sees KMLTools it looks for a file called kml\_tools.rb in  
> all of the defined load paths.
> 
> Cheers-  
> -Ezra Z.  
> Yakima Herald-Republic  
> WebMaster  
> [http://yakimaherald.com](http://yakimaherald.com)  
> 509-577-7732  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [April 17, 2006, 7:46pm UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818/5 "2006-04-17T19:46:42Z")

</div>

Wes:  
Sorry about the delay in response, i did ultimatley get this to work, i  
just  
created a kml\_tools.rb file where the framework was looking for this,  
and it  
loaded up just fine. I never did figure out WHY this happened.

Lately i hav ebeen having some file capitalization issues going on in my  
unit tests, but i think that just might be a mac os x thing.

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [March 23, 2006, 12:40am UTC](https://www.ruby-forum.com/t/maddening-library-loading-problem/54818/6 "2006-03-23T00:40:47Z")

</div>

Chris,

There appears to be a time component to my problem. If I leave my  
WEBrick server up for a few minutes, all of a sudden it can find the GEM  
and everything works.

Perhaps there is some kind of caching going on with autoloading of  
classes???

I don’t know. It’s very strange.

Wes

Wes G. wrote:

> Chris,
> 
> Did you ever find a solution for this?
> 
> I am having the exact same problem but with a RubyGem!!! (see:  
> [RubyGem loading into a controller (High quality question) - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/59088))
> 
> I will be sure to pass on any info. that I get about my problem.
> 
> Thanks,  
> Wes G.
> 
> Ezra Z. wrote:
> 
> > On Mar 14, 2006, at 8:10 AM, Alan F. wrote:
> > 
> > > As for why rails is trying to load that, I’m not sure…
> > > 
> > > Alan
> > 
> > The way rails autoloads classes these days is with const\_missing.  
> > Which is sort of like method\_missing but for constants. So they first  
> > time rails sees KMLTools it looks for a file called kml\_tools.rb in  
> > all of the defined load paths.
> > 
> > Cheers-  
> > -Ezra Z.  
> > Yakima Herald-Republic  
> > WebMaster  
> > [http://yakimaherald.com](http://yakimaherald.com)  
> > 509-577-7732  
> > removed\_email\_address@domain.invalid
