2

I am having a column price with value 10(may differ) and i need to add value 5(may differ) to the existing value 10 which is the good way to update this in rails.

Am using following rails query to find by customer_id

customer_id=25

refund_update = Refund.find_by customer_id: customer_id

4

1 に答える 1

6

値を更新するには、いくつかの方法を使用できます。

検証あり:

refund_update.increment('price', 5)

また

refund_update.update_attributes({'price': refund_update.price+5})

検証なし:

refund_update.increment!('price',5)

また

refund_update.update_attribute('price', refund_update.price+5)
于 2013-08-12T08:24:07.293 に答える