0

i have array tasks[] with items from form

<%= check_box_tag "tasks[]", task.id %>

I see them in console

Processing by TasksController#destroy as HTML
  Parameters: {"utf8"=>"?", "authenticity_token"=>"qo6JqGn0a1Yck1j67taz7kEu/ENBrwLg0xs4HbmAehNq7yMVB3llJWYgZvRNrWKPrZqYJtZIaS89EIBFIyDZTA==", "tasks"=>["7", "8"], "commit"=>"Trash All Checked", "id"=>"delete_all"}

But can't delete, action dont work

def delete_all
    Task.where(id: params[:id]).destroy_all
    redirect_to action: "index"
  end

1 Answer 1

2

Your IDs are present in params[:tasks], so you have to write something like that:

def delete_all
  Task.where(id: params[:tasks]).destroy_all

  redirect_to action: "index"
end

Anyway, I'd recommed to change tasks to tasks_ids in the view and the controller. It's a more meaningful name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.