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
You can use several ways to update the value:
with validation:
refund_update.increment('price', 5)
or
refund_update.update_attributes({'price': refund_update.price+5})
without validation:
refund_update.increment!('price',5)
or
refund_update.update_attribute('price', refund_update.price+5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With