目的:
我想将类中所有对象的数组属性重置为[].他们开始的方式.
我的尝试:
> Deal.find(:all).update_attribute('votes', [])
Run Code Online (Sandbox Code Playgroud)
结果:
返回错误.你会怎么做?
发生这种情况是因为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)
如果你需要更具体的东西.
| 归档时间: |
|
| 查看次数: |
1183 次 |
| 最近记录: |