Tôi gặp vấn đề với nhiều lần xóa bằng các hộp kiểm. khi tôi xóa nhiều bản ghi, nó sẽ nhận được các id cho các hộp kiểm nhưng nó đang chuyển một tên phương thức làm tham số và hiển thị lỗi cho tôi.Rails 3 hủy nhiều bản ghi thông qua các hộp kiểm tra
đây là mã của tôi,
**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
nó cho thấy tôi lỗi này ::::
Couldn't find Ticket with id=destroy_multiple [WHERE "tickets"."user_id" = 1]
đèo đối số ::::
{"utf8"=>"✓",
"_method"=>"delete",
"authenticity_token"=>"yHeRR49ApB/xGq1jzMTdzvix/TJt6Ysz88nuBEotHec=",
"ticket_ids"=>["11",
"12"],
"commit"=>"Delete selected",
"id"=>"destroy_multiple"}
nơi bạn sử dụng "@ticketsts" này ??? đây là hiệu chỉnh và mã hoàn hảo .... "Ticket.destroy (params [: ticket_ids])" – SSR
của nó một lỗi đánh máy, tôi đã sửa chữa nó @SSR – Radhakrishna