我有一个这样的模块:如何在自定义控制器模块使用“constantize”
module Controller
module LocaleModels
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
def locale_Lexeme; constantize_model('Lexeme') end
def locale_Synthetic; constantize_model('Synthetic') end
def locale_Property; constantize_model('Property') end
private
def constantize_model(common_part)
eval(I18n.locale.capitalize + '::' + common_part).constantize
end
end
end
end
但我一直得到
NoMethodError (undefined method `constantize' for #<Class:0x2483b0c>)
我想我不能自定义模块中使用“constantize” 。
但是,你能提供一些解决方法吗?
谢谢ryanb。 我刚刚收到了来自rails的回复:在这里说明我的错误,跟你说的一样。 其实,'eval'是我的一个错字,对不起。 但我不认为着名的'railscast'的作者实际上给了我答案。我是Railscast的一大乐趣。非常感谢你。 – boblu 2009-08-10 00:36:51