3

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

1 Answer 1

8

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.