0
votes

I am using rails 6 to load a datatables with values. My sidebar looks like this:

<li class="nav-item" >
<%= link_to users_path, {class: 'nav-link', data: {turbo: true} }  do %>
<i class="nav-icon icon-user " aria-hidden="true"></i>All Users
<% end %>
</li>

and my datatables is initialized with :

$(document).on('turbo:load', function() {

  $('#users_data_table').DataTable( {
    columnDefs: [
      {
        targets: 4,
        className: 'text-center',
      }
    ],
    stateSave: true,
    "order": [[3, 'desc']],
    "pagingType": "full_numbers",
    "dom": '<lf<t>ip>',
     bProcessing: true
     ......
 

Examples with rails and Datatables are all over the place, eg: https://www.driftingruby.com/episodes/datatables

My problem: When I click the link with data {turbo:true}, I get the following error:

DataTables warning: table id=users_data_table - Invalid JSON response.

If I disable turbo with data: {turbo:false}, datatable is initialized correctly.

Have you seen this before? Because it is driving me crazy. Why does turbo have to be disabled for this to work? I am totally baffled.

data: {turbo: true} does not work in the link_to helper it does work on the button_to helper. But to disable turbo you need data: {turbo: false} data: {turbo: true} is the default.Smek
@Smek, ok thanx. I didn't know that you have to disable turbo on link_to methods.Nick_K