This is real noob question, but after searching hard for an answer, perhaps not so noob after all: Where exactly do I put the jQuery app DataTables, so that the server side processing starts working? Cannot find the answer over at datatables.net nor here under the datatables tag. (This is using Rails 3.2.2, ruby 1.9.3p362, and datatables 1.9; all required gems appear present )
My jquery source is in public/jquery.js and in public/jquery.dataTables.js
Here’s what I have in my app/assets/javascripts/application.js:
//= require jquery
//= require_tree .
Here’s what I have in app/assets/javascripts/genotypes.js:
$(document).ready(function() {
$('#genotypes').dataTable( {
"bProcessing": true,
"bServerSide": true,
sAjaxSource: $('#genotypes').data('source')
} );
} );
Here’s index.html.erb for the relevant view:
<h1>Listing genotypes</h1>
<table id="genotypes" class="display" data-source="<%= genotypes_url(format: "json") %>">
<thead>
<tr>
<th>Marker</th>
<th>LabID</th>
<th>SubjectID</th>
<th>Box</th>
<th>Well</th>
<th>Allele1</th>
<th>Allele2</th>
<th>Run date</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<br />
<%= link_to 'New Genotype', new_genotype_path %>
So far, all that happens when I load the view for genotypes (http://localhost:3000/genotypes), I just get the column headers, and nothing else…
Any help much appreciated….
Your
javascriptfiles should live inapp/assets/javascripts/, not in the public folder.Take a look at this : http://guides.rubyonrails.org/asset_pipeline.html.
Try to move
jquery.jsinto this directory and then, like Ryan says in the Railscasts you mentioned, add this line in yourapplication.js://= require dataTables/jquery.dataTables.Do the same with your css files and give it a try.
Hope this helps.