Rails: Creating subfolders in model?
Posted
by keruilin
on Stack Overflow
See other posts from Stack Overflow
or by keruilin
Published on 2010-06-02T20:07:42Z
Indexed on
2010/06/03
10:54 UTC
Read the original article
Hit count: 183
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?
© Stack Overflow or respective owner