gpt4 book ai didi

ruby-on-rails - 通过现有值(value) rails 更新增加值(value)

转载 作者:行者123 更新时间:2023-12-02 17:42:57 25 4
gpt4 key购买 nike

我有一个 price 列,其值为 10(可能不同),我需要将值 5(可能不同)添加到现有值 10,这是在 Rails 中更新它的好方法。

我正在使用以下 Rails 查询按 customer_id 查找

customer_id=25

refund_update = Refund.find_by customer_id: customer_id

最佳答案

您可以使用多种方式来更新值:

通过验证:

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)

关于ruby-on-rails - 通过现有值(value) rails 更新增加值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18182219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com