Rails: creating subdirectories in a model?

I will have a ton of subclasses, so you want to organize them under a subfolder called stream. I added the following line to environment.rb so that all classes in the subfolder are loaded:

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

I thought that this would solve the problem in which, by convention, the model class will be placed in the appropriate module. However, when I try to call one of the classes named 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 problem is?

+3
source share
1 answer

? . - Stream && :: ?

, , . , - , , , .

-1

Source: https://habr.com/ru/post/1748228/


All Articles