I created a simple form that has a checkbox that you can select what rows you want to remove like this
= simple_form_for :user, :url => delete_selected_path, :method => :delete do |f|
%table
%tr
%td Select
%td Name
- users.each do |user|
%tr
%td= check_box_tag 'user_ids[]', user.id
%td= user.name
%tr
%td
%td= f.button :submit, 'Delete Selected'
I also created a new me called delete_selected into my controller that looks like
def delete_selected
User.where(id: params[:user_ids]).delete_all
redirect_to root_path
end
What this method does is find all the user_ids and then called delete_all
I did create a custom route as well like this
match "/pages_delete_selected" => "pages#delete_selected", :as => :delete_selected, via: :all
you can change the :all
to :delete
or anything else to make it more specific
you can find all the source code for this example here https://github.com/mzaragoza/sample_delete_multiple_records_at_once
and a live preview soon to come https://sample-delete-multiple-records.herokuapp.com/