views:

115

answers:

1

I'm going to have a ton of subclasses, so want to organize them under a subfolder called stream. I added the following line to the environment.rb so that all classes in the subfolder would be loaded:

            Rails::Initializer.run do |config|
...
            config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? }
...
    end

I thought this would solve the issue in which by convention the model class is namespaced into an according module. However, when I try to call one of the classes called stream in the stream folder, I get the following error:

NoMethodError: undefined method `new' for Stream:Module
    from (irb):28
    from /usr/local/bin/irb:12:in `<main>'

Here's the model for the parent and one child:

class Stream
end

class EventStream < Stream
end

Any idea what the issue is?

A: 

Can you post your model code? The code for the parent and at least one child model. Are you planning on doing something like Stream && Stream::Client?

I'm not sure if you are assuming that the models are going to inherit the subclass or you are adding in the subclass for each model. Just know that the models don't get nested in your code because of their placement on the file system rather the modules that a class is in, can't tell from your initial post though.

Nick Hammond
Needed to use syntax: Stream::Client
keruilin