Reputation: 2302
I'm trying to run datatables in a Rails app but it doesn't work out for me.
in my Gemfile:
gem 'jquery-datatables-rails'
gem 'jquery-rails'
gem 'bootstrap-sass'
Shell command to check presence:
gem list | grep -i datatables
jquery-datatables-rails (1.12.2)
application.css:
*= require dataTables/jquery.dataTables
application.js
//= require dataTables/jquery.dataTables
clients.js
jQuery ->
$('#clients').dataTable()
Should init datatables right?
Firebug errors:
TypeError: $(...).dataTable is not a function
$('#clients').dataTable();
or:
ReferenceError: jQuery is not defined
$('#clients').dataTable({
Any ideas? thanks for your time.
Upvotes: 1
Views: 804
Reputation: 967
I had a similar error message recently. First of all, do you set the id in your table tag? Do you have thead and tbody tag in your table?
<table id='clients'>
<thead>
<tr>
<th>...</th>
</tr>
</thead>
<tbody>
<% @clients.each do |client| %>
<tr>
<td>...</td>
</tr>
</tbody>
</table>
Second: You are using ->
symbol, that is CoffeeScript replacement of function keyword, besides CoffeeScript is tab sensitive. Make sure that your CoffeeScript file name end with .coffee
. I would try with tab and changing the file name.
clients.js.coffee
jQuery ->
$('#clients').dataTable()
Maybe with these changes you would end with your DataTable working.
Upvotes: 1