我正在努力做到这一点
User.find([23,45,68,123]).update_all(:is_active => true)
但我得到:
NoMethodError: undefined method `update_all' for #<Array:0x00000007493778>
正确的语法是什么?如果不需要的话,我宁愿不重复每一个.
我正在努力做到这一点
User.find([23,45,68,123]).update_all(:is_active => true)
但我得到:
NoMethodError: undefined method `update_all' for #<Array:0x00000007493778>
正确的语法是什么?如果不需要的话,我宁愿不重复每一个.
find
返回一个数组,因此不能使用update_all
.
为了解决这个问题,我认为可以使用where
,它返回ActiveRecord::Relation
,所以update_all
应该可以:
User.where(:id =>[23,45,68,123]).update_all(:is_active => true)
http://apidock.com/rails/ActiveRecord/Relation/update_all
我希望这有帮助...