I have a module stat that exists in the directory structure: lib/stat_creator/stat/
In lib/stat_creator/stat.rb I have the files in the lib/stat_creator/stat/ directory that I require, as well as:
module StatCreator
module Stat
end
end
When I use that module I refer to the classes as
StatCreator::Stat::Foo.new
Now I want a root Stat class that lives in app. I've made my Stat class in app/models an开发者_JS百科d set it up in routes.rb. But if I go to rails console and try to use the Stat class in app/models like:
Stat.by_user_id("ID")
I get the error: LoadError: Expected ../lib/stat_creator/stat.rb to define Stat
I thought the point of using namespaces was to avoid this kind of conflict, so I don't understand what I"m doing wrong.
I'd do:
::Stat.by_user_id("ID")
精彩评论