Rails datatables refresh javascript

Hi

I followed a railscast episode and got datatables up and running,
beautifully along with the nice jquery-ui as in the front page.

The main issue I’m having though is that I suck at CoffeeScript/JS ~_~

I’m trying get the datatables to reload every 1 second but I dont see
any
request coming into my webserver for refreshes and hence, no refreshes
on
the web page itself.

Here’s my code:

app/assets/javascripts/comments.js.coffee

jQuery ->
  $('#comments_id').dataTable
    sPaginationType: "full_numbers"
    bJQueryUI: true
    bProcessing: true
  setInterval('$("#comments_id").dataTable().fnDraw()', 1000);

And here is the code that gets generated on the client side:

(function() {

  jQuery(function() {
    $('#comments_id').dataTable({
      sPaginationType: "full_numbers",
      bJQueryUI: true,
      bProcessing: true
    });
    return setInterval('$("#comments_id").dataTable().fnDraw()', 1000);
  });

}).call(this);

Help will be appreciated. :slight_smile:

Heptagone H wrote in post #1093275:

app/assets/javascripts/comments.js.coffee

jQuery ->
>   $('#comments_id').dataTable
>     sPaginationType: "full_numbers"
>     bJQueryUI: true
>     bProcessing: true
>   setInterval('$("#comments_id").dataTable().fnDraw()', 1000);

Take a look at the documentation for setInterval():

Looking at the function signature:

setInterval(code,millisec,lang)

code = The function that will be executed.

You have passed a string for this argument. You can’t call a string.

Solution: Give setInterval a function as is expected:

In JavaScript it should look something like:
setInterval(function() {
$(“#comments_id”).dataTable().fnDraw();
}, 1000);