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
> 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 -- Posted via http://www.ruby-forum.com/.
On Mar 14, 2006, at 8:10 AM, Alan Francis wrote:> >> 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 >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
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-- Posted via http://www.ruby-forum.com/.
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-- Posted via http://www.ruby-forum.com/.
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. On 3/22/06, Wes Gamble <weyus@att.net> wrote:> > 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 > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060417/b9a9d975/attachment.html