Ruby on rails 如何从表中更新状态字段
我想将Ruby on rails 如何从表中更新状态字段,ruby-on-rails,Ruby On Rails,我想将status列更新为paid,其中status column=“closed”位于我的Subscriptions表中。 谢谢你的帮助 我试过这样做 订阅。其中(:status=>'closed')。更新(:status=>'paid') 但不工作更新 请尝试使用以下代码: Subscription.where(:status =>'closed').update_all(:status => 'paid') 或 我想你的模型是订阅,但不是订阅 所以你应该试试 Subscrip
status
列更新为paid,其中status column=“closed”位于我的Subscriptions
表中。
谢谢你的帮助
我试过这样做
订阅。其中(:status=>'closed')。更新(:status=>'paid')
但不工作更新 请尝试使用以下代码:
Subscription.where(:status =>'closed').update_all(:status => 'paid')
或
我想你的模型是
订阅
,但不是订阅
所以你应该试试
Subscription.where(status: 'closed').update_all(status: 'paid')
但不是
Subscriptions.where(status: 'closed').update_all(status: 'paid')
但是,如果您想让记录运行回调(例如:您在保存方法之后设置了一些),您应该使用下面的脚本来调用回调
Subscription.where(status: 'closed').each{ |s| s.update(status: 'paid') }
希望这有帮助,谢谢
Subscription.where(status: 'closed').each{ |s| s.update(status: 'paid') }