RubyActiveRecordEasyOne:按变量调用属性

RubyActiveRecordEasyOne:按变量调用属性,ruby,activerecord,Ruby,Activerecord,我想更新activerecord模型中由变量定义的属性 这是我的方法 def increment_attribute(attr_name) self.attribute(attr_name).increment end 这不起作用,因为属性是私有activerecord方法 我该怎么做?谢谢 def increment_attribute(name) self.send(name).increment end

我想更新activerecord模型中由变量定义的属性

这是我的方法

def increment_attribute(attr_name)
  self.attribute(attr_name).increment
end
这不起作用,因为属性是私有activerecord方法

我该怎么做?谢谢

def increment_attribute(name)
  self.send(name).increment
end