0

I would like to make an extension which injects code into a specific site allowing the user to delete multiple posts at once instead of having to delete them manually one at a time.

The element that seems to trigger the removal looks like this:

<a class="button delete link" rel="nofollow" data-method="delete" href="/relative-path">Yes</a>

Now I know nothing about rails, but once I identify all of these elements is there a way I can cause them to be triggered via javascript?

Thanks!

MZaragoza
  • 10,108
  • 9
  • 71
  • 116
i3rendn4v05
  • 539
  • 1
  • 4
  • 12
  • you need to find the code that catches the clicks, and expand it to take a list of urls instead of just one. chrome devtools event breakpoints sound ideal to get started. – dandavis Mar 06 '16 at 04:27

1 Answers1

0

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/

MZaragoza
  • 10,108
  • 9
  • 71
  • 116