I have array selected_ids[] with items id from form, and see them in console when click on the button, but can't delete them in action.
My form:
<% for task in @tasks.where(active: true) %>
<li class="task">
<%= check_box_tag 'selected_ids[]', task.id, false, class: 'selectable' %>
<%= link_to task.title, task, class: "task-title text-dark" %>
</li>
<% end %>
</ul>
My action:
def delete_all
Task.where(id: params[:selected_ids]).destroy_all
@tasks = Task.where(user_id: current_user)
render "index"
end
My routes:
resources :tasks do
get :delete_all, on: :collection
end
Console, when click button:
Started DELETE "/tasks/delete_all" for 127.0.0.1 at 2019-01-18 10:44:18 +0200
Processing by TasksController#destroy as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"3BlLqPDnC9IzaVqnCv6qO0KkKP7VNBU9yEnmm8eAKyb76f5eCEIYUq9Gxx4YNbtbcJo0AEi2c/ORs2E87sg0Aw==", "commit"=>"Delete selected", "selected_ids"=>["2", "1"], "id"=>"delete_all"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
? app/controllers/tasks_controller.rb:2
Task Load (0.3ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? ORDER BY "tasks"."id" ASC LIMIT ? [["id", 0], ["LIMIT", 1]]
? app/controllers/tasks_controller.rb:101
Rendering public/404.html within layouts/application
Rendered public/404.html within layouts/application (0.4ms)
Filter chain halted as :set_task rendered or redirected
Completed 404 Not Found in 682ms (Views: 676.8ms | ActiveRecord: 0.6ms)
Aucun commentaire:
Enregistrer un commentaire