我使用的是rails 4.2.4,在生成了一个基本的产品支架之后,我似乎无法获得gem jquery-datatables rails。我正在使用github自述和铁路节目试图让它在没有运气的情况下工作。
http://railscasts.com/episodes/340-datatables
https://github.com/rweng/jquery-datatables-rails
Gemfile
gem 'jquery-datatables-rails', '~> 3.3.0'application.js
//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require turbolinks
//= require_tree .
jQuery -> $('.datatable').DataTable();application.css
*= require dataTables/jquery.dataTables
*= require_tree .
*= require_selfindex.html.erb
<table class="datatable">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td><%= product.name %></td>
<td><%= product.price %></td>
</tr>
<% end %>
</tbody>
</table>我已经尝试直接引用github回购在我的宝石文件。generate似乎没有以任何一种方式正确地添加需求,所以我已经手动地添加了它们。
发布于 2016-01-09 01:41:59
通过将此脚本放入视图中,设法修复了这个问题。
<script>
$(document).ready(function() {
$('.datatable').dataTable();
} );
</script>发布于 2018-08-22 08:49:34
对于未来的读者,您可以这样做,而不是上面接受的答案。您可以直接将其转储到您的appliation.js文件中--我不喜欢像上面的答案那样将脚本放在视图中的想法:
添加到Application.js中
$(document).ready(function(){
$("table[role='datatable']").each(function(){
$(this).DataTable({
processing: true
});
});
})不要忘记在html表中添加一个角色=‘datatable’。

https://stackoverflow.com/questions/34685587
复制相似问题