1

Rails Console

q=Article.last(3)
q.delete

wrong number of arguments (0 for 1) 

q.destroy

NoMethodError: undefined method `destroy' for #<Array:0x0000000901b6d0>
Timmy Von Heiss
  • 2,160
  • 17
  • 39

2 Answers2

2

Try

Article.destroy_all(id: q.map(&:id))

OR

Article.destroy q.map{ |a| a.id }
ashvin
  • 2,020
  • 1
  • 16
  • 33
2

You can use destroy_all

q = Article.order(id: :desc).limit(3)
q.destroy_all

or With your approach

q = Article.last(3) 
q.map(&:destroy)
# or
Article.where(id: q.map(&:id)).destroy_all

You can also chain destroy_all to where

Article.where(some_condition).destroy_all
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88