Rails Console
q=Article.last(3)
q.delete
wrong number of arguments (0 for 1)
q.destroy
NoMethodError: undefined method `destroy' for #<Array:0x0000000901b6d0>
Rails Console
q=Article.last(3)
q.delete
wrong number of arguments (0 for 1)
q.destroy
NoMethodError: undefined method `destroy' for #<Array:0x0000000901b6d0>
Try
Article.destroy_all(id: q.map(&:id))
OR
Article.destroy q.map{ |a| a.id }
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