[英]Rails: Overriding const_missing within a module
在我的Rails應用程序中,我有一個這樣定義的模塊:
module WhateverModule
class WhateverClass
...
end
end
該文件(whatever_class.rb)位於/ app / models / whatever_module下
const_missing
被Rails覆蓋,盡管我做了一些變通方法,其中涉及初始化程序,但我希望我能以更好的方式實現它。
我的目標是通過自定義const_missing
方法來解決WhateverModule :: Foo(Foo未定義)的問題。
任何幫助將不勝感激。 提前致謝!!
以下內容在Rails 2.2.2中對我來說似乎很好
module WhateverModule
def self.const_missing(c)
# handle missing constant
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.