ruby activerecord easy one:通过变量调用属性

时间:2012-03-31 10:32:34

标签: ruby activerecord

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

这是我的方法

def increment_attribute(attr_name)
  self.attribute(attr_name).increment
end

这不起作用,因为属性是私有的activerecord方法

我该怎么做?谢谢!

1 个答案:

答案 0 :(得分:3)

def increment_attribute(name)
  self.send(name).increment
end
相关问题