Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
store.widgets.clear似乎没有保存到数据库中。所以我尝试了:
store.widgets.clear
store.widgets.each do |i| i.destroy end
这只会破坏数据库中一半的记录。关于如何删除整个商店收藏的任何建议?
我需要添加一个 .destroy_all (或让 .clear 这样做),但还没有解决它。您对 .each 看到的问题是它在删除时遍历数组。现在你可以这样做:
store.widgets.reverse.each(&:destroy)
我会优先考虑destroy_all。