On Fri, May 7, 2010 at 3:26 AM, Andy Joel <li...@ruby-forum.com> wrote: > Thanks for the reply >> On Thu, May 6, 2010 at 6:58 AM, Andy Joel <li...@ruby-forum.com> wrote: >>> I have my models and controllers set up in sub-folders, so, for example, >>> sample.rb is in app/models/sample_log, and samples_controller.rb is in >>> app/controllers/sample_log. The controllers are defined to be within a >>> namespace just though the class name, eg like this: >>> >>> class SampleLog::SamplesController < SampleLog::SuperController >>> >>> However, the models are not. >>> >>> class Sample < ActiveRecord::Base >> >> >> Where is this file? I'm guessing that it's in >> app/models/sample_log/sample.rb ? > Yes >> >>> Expected R:/samplelog/app/models/sample_log/sample.rb to define >>> SampleLog::Sample >> >> What this is saying is that Rails tried to find a class or module >> SampleLog::Sample > Is that right? I think it is the other way around; it is trying to find > Sample, but objects because it thinks it should be in sample.rb, not > sample_log/sample.rb. > > "SampleLog::Sample" is not used anywhere in the project (and I have done > a search to confirm this). > > app/controllers/sample_log/samples_controller.rb:11:in `home' > > Here are lines 10 to 12 > > def home > �...@samples = Sample.find :all > end
Basic Ruby lesson. You have class SampleLog::SamplesController << .... def home @samples = Sample.find :all end end When Ruby needs to figure out what Sample means in that home action, it first looks for a constant in the current namespace so it looks for SampleLog::SamplesController::Sample Rails catches this as a missing constant and tries to find a file under one of the load paths sample_log/samples_controller/sample.rb but doesn't find one so it hands the problem back to Ruby, which then tries to find the constant Sample one step up the namespace chain and looks for SampleLog::Sample. Now rails looks for sample_log/sample.rb and finds it, and loads it, and then checks to see whether SampleLog::Sample is now defined, which it isn't because that file defined ::Sample instead. Did you try just moving app/models/sample_log/sample.rb to app/models/sample.rb as I suggested, I'm pretty sure that doing this, and possibly removing the the stuff you did to monkey with the load paths behind Rails back should fix your problem. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.