mkhairi / jquery-datatables

Jquery datatables ruby gems for assets pipeline
https://datatables.net/
Other
76 stars 17 forks source link

Does not function with Rails 6.0.2.2 #19

Open Vorkosigan76 opened 4 years ago

Vorkosigan76 commented 4 years ago

I tried to make this gem work with Rails 6.0.2.2 (where the javascript have moved from assets/javascript to their own javascript folder - which is why the installer does not work)... without success

What I did is:

Modify javascript/packs/application.js

//= require jquery
//= require popper
//= require bootstrap-sprockets
//= require datatables

Create javascript/packs/datatables.js

//Core component
//= require datatables/jquery.dataTables
//Bootstrap4 theme
//= require datatables/dataTables.bootstrap4

And the datatables javascript is not loaded, which leads to the following:

$(...).DataTable is not a function TypeError: $(...).DataTable is not a function

What should I do?

mkhairi commented 4 years ago

@Vorkosigan76, Rails 6 has added Webpacker as the default JavaScript compiler instead of Sprockets. See readme

mkhairi commented 4 years ago

if you still want to use with sprockets, you need to recreate javascripts folder in app/assets/ and update app/assets/config/manifest.js to tell sprockets load those folders.

this default sprockets manifest in previous rails version

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

and dont forget to add this in your layout file <%= javascript_include_tag "application", "data-turbolinks-track" => true %>