如何在IRB中更新类的所有属性?

Tri*_*rip 1 ruby-on-rails irb

目的:

我想将类中所有对象的数组属性重置为[].他们开始的方式.

我的尝试:

> Deal.find(:all).update_attribute('votes', [])
Run Code Online (Sandbox Code Playgroud)

结果:

返回错误.你会怎么做?

rob*_*okl 5

发生这种情况是因为find(:all)返回一个数组.

你可以做:

Deal.update_all :votes => []
Run Code Online (Sandbox Code Playgroud)

要么

Deal.all.each { |d| d.update_attribute(:votes, []) }
Run Code Online (Sandbox Code Playgroud)

如果你需要更具体的东西.