我正在使用Rails 5,我想刪除一組對象。在之前的一篇文章中,我讀到「destroy_all」是真相和光明。我有對象的兩個數組,我減去獲得的第三陣列在Rails中,如何刪除數組中的所有對象?
unused_currencies = all_currencies - currencies_from_feed
unused_currencies.destroy_all
但使用destroy_all
當我得到這個錯誤:
NoMethodError: undefined method `destroy_all' for #<Array:0x007feea8878770>
什麼定義'currency_from_feed'假設'all_currencies'實際上是'Currency.all',可能有一個乾淨的範圍可以寫成處理「unused_currencies」的集合,然後它很簡單'Currency.unused_currencies.destroy_all'但沒有額外的信息,它將很難幫助 – engineersmnky