Forum: Ruby on Rails Maddening library loading problem

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.
9ea7cf7de125a4ecb81f3ece95d220b5?d=identicon&s=25 Chris Martin (Guest)
on 2006-03-14 17:07
(Received via mailing list)
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
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-03-14 17:10
> 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
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-03-14 21:06
(Received via mailing list)
On Mar 14, 2006, at 8:10 AM, Alan Francis 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 Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-23 00:26
Chris,

Did you ever find a solution for this?

I am having the exact same problem but with a RubyGem!!! (see:
http://www.ruby-forum.com/topic/59088)

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

Thanks,
Wes Gamble

Ezra Zygmuntowicz wrote:
> On Mar 14, 2006, at 8:10 AM, Alan Francis 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 Zygmuntowicz
> Yakima Herald-Republic
> WebMaster
> http://yakimaherald.com
> 509-577-7732
> ezra@yakima-herald.com
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-23 00:40
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 Gamble wrote:
> Chris,
>
> Did you ever find a solution for this?
>
> I am having the exact same problem but with a RubyGem!!! (see:
> http://www.ruby-forum.com/topic/59088)
>
> I will be sure to pass on any info. that I get about my problem.
>
> Thanks,
> Wes Gamble
>
> Ezra Zygmuntowicz wrote:
>> On Mar 14, 2006, at 8:10 AM, Alan Francis 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 Zygmuntowicz
>> Yakima Herald-Republic
>> WebMaster
>> http://yakimaherald.com
>> 509-577-7732
>> ezra@yakima-herald.com
9ea7cf7de125a4ecb81f3ece95d220b5?d=identicon&s=25 Chris Martin (Guest)
on 2006-04-17 19:46
(Received via mailing list)
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.
This topic is locked and can not be replied to.