我有使用复选框进行多次删除的问题。当我删除多条记录时,它会获取复选框的 id,但它会将方法名称作为参数传递并显示错误。
这是我的代码,
**In my Controller method :**
def destroy
@ticket = current_user.tickets.find(params[:ticket_ids])
@ticket.destroy
respond_to do |format|
format.html { redirect_to tickets_url }
format.json { head :no_content }
end
end
def destroy_multiple
Ticket.destroy(params[:tickets])
respond_to do |format|
format.html { redirect_to tickets_path }
format.json { head :no_content }
end
end
**In my index.html.erb**
<%= form_tag destroy_multiple_tickets_path, method: :delete do %>
.
.
<td class="table-icon">
<%= check_box_tag "ticket_ids[]", ticket.id %>
</td>
.
.
<%= submit_tag "Delete selected" %>
**In routes.rb**
resources :tickets do
collection do
delete 'destroy_multiple'
end
end
它向我显示了这个错误::::
Couldn't find Ticket with id=destroy_multiple [WHERE "tickets"."user_id" = 1]
通过争论 ::::
{"utf8"=>"✓",
"_method"=>"delete",
"authenticity_token"=>"yHeRR49ApB/xGq1jzMTdzvix/TJt6Ysz88nuBEotHec=",
"ticket_ids"=>["11",
"12"],
"commit"=>"Delete selected",
"id"=>"destroy_multiple"}