我已经按照以下教程在我的Rails应用程序中设置了DataTables,但我没有看到任何变化。以下是我关注的内容:
https://github.com/rweng/jquery-datatables-rails
http://railscasts.com/episodes/340-datatables
我没有收到错误。我只是没有看到任何变化。然后我重新启动了我的服务器。
应用.js
//= require dataTables/jquery.dataTables
应用.css
*= require dataTables/jquery.dataTables
视图:
<table id="products">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Something</td>
<td>Something</td>
</tr>
<tr>
<td>Something</td>
<td>Something</td>
</tr>
<tr>
<td>Something</td>
<td>Something</td>
</tr>
</tbody>
</table>
产品.js.咖啡
jQuery ->
$('#products').dataTable
我只想能够对列进行排序。为什么这不起作用?
尝试将 Products.js.coffee 转换回常规 JavaScript,看看结果是否相同。如果是这样,问题要么出在 javascript 本身,要么出在 coffeescript 的编译上(确保 coffee-rails gem 在 Gemfile 中)。另请查看RailsCast Coffeescript Episode。