문제

Objective:

I would like to reset the array attribute of all 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 => []
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top