私のアプリケーションコードは、Rails3.2で以下に示すように構成されています。Railsコンソールにアクセスして入力Foo::Bar::FooBar
すると、次の警告が返されます。
warning: toplevel constant FooBar referenced by Foo::Bar::FooBar
それらが配置されているアプリケーションコードとファイル:
# app/models/foo/bar/foo_bar.rb
module Foo
class Bar
class FooBar
end
end
end
# app/models/foo/bar.rb
module Foo
class Bar
end
end
# app/models/foo_bar.rb
class FooBar
end
自動ロードパスは、Railsのデフォルトから変更されていません。
この問題を修正する方法の1つは、に次のコードを追加することFoo::Bar::FooBar
です。しかし、それは汚れているように感じ、問題を解決するための構成オプションまたは私が間違っている他の何かがあるかどうか疑問に思いました。
# app/models/foo/bar/foo_bar.rb
module Foo
# This line of code removes the warning and makes class methods execute
# on the Foo::Bar::FooBar class instead of the FooBar class.
class Bar; end
class Bar
class FooBar
end
end
end