1
導軌控制檯如何在滑軌控制檯刪除某個範圍內(散列)
Q = Article.last(3)
q.delete
wrong number of arguments (0 for 1)
q.destroy
NoMethodError: undefined method `destroy' for #<Array:0x0000000901b6d0>
導軌控制檯如何在滑軌控制檯刪除某個範圍內(散列)
Q = Article.last(3)
q.delete
wrong number of arguments (0 for 1)
q.destroy
NoMethodError: undefined method `destroy' for #<Array:0x0000000901b6d0>
您可以使用destroy_all
q = Article.order(id: :desc).limit(3)
q.destroy_all
或你的方法
q = Article.last(3)
q.map(&:destroy)
# or
Article.where(id: q.map(&:id)).destroy_all
你也可以連接destroy_all
到where
Article.where(some_condition).destroy_all
嘗試
Article.destroy_all(id: q.map(&:id))
OR
Article.destroy q.map{ |a| a.id }