How to Destroy multiple objects simultaneously in Rails 3

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)