我的rails模型具有试图define_method(method_name)进入模型内部的代码.
我一直在:
NoMethodError: undefined method `define_method'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我是在错误的地方做这件事吗 我需要附加到此模型的此方法.我还能在哪里定义这种方法?
编辑:对于那些要求查看代码的人:
for field in rdev_fields
next if self.attributes.include?(field)
count = count + 1
rdev_hash[field.to_sym] = self.attributes["attribute#{count}"]
if !self.respond_to?(field) then
define_method("#{field}") do
self.send("attribute#{count}".to_sym)
end
end
end
Run Code Online (Sandbox Code Playgroud)