How to get dynatable json rails to work

997 Views Asked by At

Im trying to get dynatable to ajax load json with rails but I get an error I need help explaining. How do I set this up?

CONSOLE

TypeError: 'undefined' is not an object (evaluating 'settings.dataset.records.length')

THE LOG

Started GET "/subjects/index.json?page=1&perPage=10&offset=0" for 127.0.0.1 at 2014-01-25 23:20:47 +0100
Processing by SubjectsController#index as JSON
  Parameters: {"page"=>"1", "perPage"=>"10", "offset"=>"0"}
  Subject Load (3.0ms)  SELECT "subjects".* FROM "subjects"
Completed 200 OK in 3035ms (Views: 0.1ms | ActiveRecord: 3.0ms)
[2014-01-25 23:20:50] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

SUBJECT.JS

jQuery(document).ready(function() {
      $('#subjects-table').dynatable({
        table:{
                defaultColumnIdStyle: 'underscore',
        },

      dataset: {
        ajax: true,
        ajaxUrl: '/subjects/index.json',
        ajaxOnLoad: true,
        contentType: "application/json; charset=utf-8",
        records: []

      }

    });
});    

Subjects_controller

class SubjectsController < ApplicationController

    def index
        @subjects = Subject.all
        respond_to do |format|
            format.html
            format.json {render :json => @subjects.to_json}
        end
    end

end
1

There are 1 best solutions below

0
On

Look how should look like AJAX response: http://www.dynatable.com/dynatable-ajax.json to be processed.