1
我正在制作一个插件,我需要它来覆盖我的模型的setter/getter。这里是我到目前为止的代码:rails 3覆盖模型设置器
module Iplong
extend ActiveSupport::Concern
module ClassMethods
...
def override_setter
self.class_eval %(
def #{attribute}=(raw_value)
self[:#{attribute}] = #{ip2long('raw_value')}
end
)
end
end
end
ActiveRecord::Base.send :include, Iplong
通知的raw_value
PARAM。如果我将它打印在评估代码中,它将打印出属性设置时出现的正确值,但如果我在ip2long
函数中打印它,它将返回一个字符串:raw_value
,那么如何在不解释它的情况下传递此参数作为字符串?
尝试,但我得到'未定义的局部变量或方法'RAW_VALUE”为#<类别:0x00000003bc72a0>' – 2012-07-13 17:49:04
不知道在哪里概率。可能是,但我编辑答案,包括一些示例代码,应该可以帮助你明白我的意思。 – 2012-07-13 17:59:04