How to Destroy multiple objects simultaneously in Rails 3

后端 未结 5 545
慢半拍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:54

    I had exactly the same problem, but the solution here did not work for me in rails 5.1.6.

    Perhaps you pass parameter params[:ids] in the wrong way.

    Here's how I fix it.

    Before

    Model.where(:id => params[:ids]).destroy_all
    

    After

    ids = params[:ids].split(",")
    Model.where(:id => ids).destroy_all
    

提交回复
热议问题