1

我使用的鐵軌4.2.4,並生成一個基本的產品支架後,我似乎無法獲得寶石jQuery的數據表護欄。我使用的是GitHub的自述與railscast插曲一起嘗試,並得到它,沒有運氣的工作都沒有。jQuery的數據表 - 軌道的寶石不是在申請表

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_self 

index.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> 

我已經嘗試過直接在我的Gemfile引用GitHub庫。在生成安裝似乎並沒有添加需要妥善無論哪種方式,所以我已經把他們的手工。

回答

2

管理人把這個腳本到視圖

<script> 
    $(document).ready(function() { 
    $('.datatable').dataTable(); 
    }); 
</script> 
+0

有同樣的問題,解決這個問題,但它不是爲我工作。我遵循你的解決方案,但仍然沒有工作 –