0

Rails 3.1にあるとしましょう:

class Category < ActiveRecord::Base
  has_many :items
end

class Item < ActiveRecord::Base
  belongs_to :category
end

私は何かをしたいです

cat=Category.find(1)
cat.items.is_enabled=true
cat.save

しかし、ループを介してそれぞれを設定することはできず、設定する必要があります。これらを一度に設定する方法はありますか?

どうも

4

1 に答える 1

0

試す

 cat.items.update_all(:is_enabled => true)
于 2012-11-08T05:13:44.833 に答える