Thanks for the reply
> On Thu, May 6, 2010 at 6:58 AM, Andy Joel <[email protected]> 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
>
>> Instead, I have added the relevant directories to config.load_paths in
>> environment.rb.
>
> Which may be part of the problem. You might well be fighting
> convention over configuration.
>
>> 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).
>
> What rails does here is to look for samplelog/sample.rb somewhere in
> the various load paths. It's finding app/models/sample_log/sample.rb
> which if it indeed contains:
>
> class Sample < ActiveRecord::Base
>
> outside of a class or module block is definining ::Sample, not
> ::SampleLog::Sample.
>
> I'm guessing that moving app/models/sample_log/sample.rb to
> app/models/sample.rb will fix this.
Yes, I think this is true (indeed, this is how it was originally set
up). However, I was HOPING to be able to split the models into sections.
>
> If not then show us the walkback you get on the error, it should point
> to some piece of code which is referring to some constant
> (name_space::)*Sample
R:/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:428:in
`load_missing_constant'
R:/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in
`const_missing_with_dependencies'
R:/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:439:in
`load_missing_constant'
R:/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:93:in
`const_missing'
app/controllers/sample_log/samples_controller.rb:11:in `home'
Here are lines 10 to 12
def home
@samples = Sample.find :all
end
--
Posted via http://www.ruby-forum.com/.
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.