1
我想更新activerecord模型中變量定義的屬性。ruby activerecord簡單之一:通過變量調用屬性
這是我的方法
def increment_attribute(attr_name)
self.attribute(attr_name).increment
end
這不起作用,因爲屬性是私有的ActiveRecord方法
我應該怎麼辦呢?謝謝!
我想更新activerecord模型中變量定義的屬性。ruby activerecord簡單之一:通過變量調用屬性
這是我的方法
def increment_attribute(attr_name)
self.attribute(attr_name).increment
end
這不起作用,因爲屬性是私有的ActiveRecord方法
我應該怎麼辦呢?謝謝!
def increment_attribute(name)
self.send(name).increment
end