我正在rails 6
应用上创建多个删除功能。
到目前为止,这是我已经完成的步骤。
destroy_multiple
方法def destroy_multiple
Page.destroy(params[:page_ids])
redirect_to pages_path
end
config->routes.rb
resources :pages do
collection do
delete 'destroy_multiple'
end
end
已安装gem 'select_all-rails'
在我的app->javascript->application.js
中,我包括了选择所有rails js所需的代码:
require("@rails/ujs").start()
Require ("turbolinks"). start ()
require("@rails/activestorage").start()
require("channels")
require("select_all.js")
$(function() {
$("#selectAll").select_all();
});
import 'bootstrap'
import './stylesheets/application.scss'
<section>
<div class="container-fluid">
<!-- Page Header-->
<header>
<h1 class="h3 display">Pages</h1>
</header>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h4>List of Pages</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<%= form_tag destroy_multiple_pages_path, method: :delete do %>
<table class="table">
<thead>
<tr>
<th data-sort-ignore="true"> <input type="checkbox" id="selectAll"/></th>
<th>Id</th>
<th>Title</th>
<th>Summary</th>
<th>Date Created</th>
<th colspan="3">Action</th>
</tr>
</thead>
<tbody>
<% @pages.each do |page| %>
<tr>
<td><%= check_box_tag "pages_ids[]", page.id, false, class: 'selectable' %> </td>
<td><input type="checkbox" value="false"> </td>
<td scope="row"><%= page.id %></td>
<td><%= page.title %></td>
<td><%= page.body.truncate(60) %></td>
<td> <%= page.created_at.strftime("%B %d, %Y") %> </td>
<td><%= link_to "Show", page_path(page)%></td>
<td><%= link_to "Edit", edit_page_path(page)%></td>
<td><%= link_to "Delete", page_path(page), method: :delete, data: { confirm: "Are you sure?" }%></td>
</tr>
<% end %>
</tbody>
</table>
<%= submit_tag "Delete Selected", class: 'btn btn-primary btn-xs' %>
<% end %>
</div>
</div>
</div>
</div>
运行此命令时,它会正确显示我的复选框。但是,当我单击顶部的复选框时,并没有全部选中,单击删除按钮后出现此错误:
Couldn't find Page without an ID
知道我在做什么错吗?