在我的Rails应用程序中,我有一个以这种方式定义的模块:
module WhateverModule
class WhateverClass
...
end
end
此文件(whatever_class.rb)位于/ app / models / whatever_module
下 Rails正在覆盖 const_missing
,尽管我做了一些解决方法,涉及初始化程序,但我希望我能以更好的方式实现它。
我的目标是通过自定义const_missing
方法解决WhateverModule :: Foo(Foo未定义)。
任何帮助将不胜感激。在此先感谢!!
答案 0 :(得分:1)
以下似乎在Rails 2.2.2
中对我有用module WhateverModule
def self.const_missing(c)
# handle missing constant
end
end