开发者

How do I update all attributes of a class in IRB?

Objective:

I would like to reset the array attribute of a开发者_运维知识库ll objects in a class to []. The way they started.

My attempt:

> Deal.find(:all).update_attribute('votes', [])

Outcome:

Returns an error. How would you do this?


This happens because find(:all) returns an array.

You can do:

Deal.update_all :votes => []

or

Deal.all.each { |d| d.update_attribute(:votes, []) }

if you need something more specific.


Deal.update_all :votes => []
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜