How to Destroy multiple objects simultaneously in Rails 3

后端 未结 5 456
慢半拍i
慢半拍i 2020-12-13 23:13

I have a Rails application that is trying to delete multiple objects at a time.

I have tried like sending set of id seperated by \',\' to rails destroy method,but it

5条回答
  •  有刺的猬
    2020-12-13 23:51

    destroy_all destroys the records matching conditions by calling destroy method for each instantiating record. So object’s callbacks are executed.

    Model.destroy_all(:status => "inactive")
    Model.where(:id => [1,2,3,4,5]).destroy_all
    Model.where(:id => 1..5).destroy_all
    

    UPDATE

    User.where(:id => params[:ids]).destroy_all
    
    /users?ids[]=1&ids[]=2&ids[]=3
    

提交回复
热议问题