Rails 6 and selectize

Viewed 723
1 Answers

Add selectize to your packages:

yarn add selectize

Add this line to your javascript/packs/application.js

require("selectize")

Add the code necessary to initialize the jQuery plugin (you could also add this to your application.js file if you wanted to):

$(document).on("turbolinks:load", function() {
  $(".selectize").selectize()
})

Make sure your <select> has the matching selectize class that you just defined.

To import the selectize styles, add these lines to your webpack stylesheet:

@import "~selectize/dist/css/selectize";
@import "~selectize/dist/css/selectize.default";
Related