Ask A Question


You’re not receiving notifications from this thread.

How Do I Use Selectize in Rails 6

Jeremy Bray asked in Gems / Libraries

Hi there, I really love the selectize tutorial and would love to use it in a rails 6 application. What changes do I need to make to the tutorial.

can i just change

//= require selectize


$ yarn add selectize

Do I need to add Selectize to my environment.js like i would jquery

const webpack = require('webpack')
  new webpack.ProvidePlugin({
    $: 'jquery/src/jquery',
    jQuery: 'jquery/src/jquery',
        selectize: '?'

And or Require selectize in application.js file.


Hi @Jeremy, the following implementation works well for me in Rails 6:

yarn add selectize


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



javascript/packs/language.js (code from video)

$(document).on("turbolinks:load", function() {
    var selectizeCallback = null;

    $(".language-modal").on("", function(e) {
        if (selectizeCallback != null) {
            selectizeCallback = null;


    $("#new_language").on("submit", function(e) {
            method: "POST",
            url: $(this).attr("action"),
            data: $(this).serialize(),
            success: function(response) {
                selectizeCallback({value:, text:});
                selectizeCallback = null;


        create: function(input, callback) {
            selectizeCallback = callback;


and finally the view on edit.html.erb

          <%= :language_ids, Language.all.pluck(:name, :id), {}, { multiple: true, class: "selectize" } %>

                    <div class="modal fade language-modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="mySmallModalLabel">Add Language</h4>
      <div class="modal-body">
        <%= form_for do |f| %>
          <div class="form-group">
            <%= f.label :name %>
            <%= f.text_field :name, class: "form-control" %>
          <div class="form-group">
            <%= f.submit class: "btn btn-primary" %>
        <% end %>

That's it - hope it helps. Cheers


Thank you for that answer.

I would like to use TailwindCSS, instead of Bootstrap. What changes should I make to this code? or would that code work without Bootstrap installed. Currently I try to work it out and I get an error.

submissions.js:33 Uncaught TypeError: $(...).modal is not a function
at Selectize.create (submissions.js:33)
at Selectize.createItem (selectize.js:2196)
at Selectize.onOptionSelect (selectize.js:1235)
at HTMLDivElement. (selectize.js:687)
at HTMLDivElement.dispatch (jquery.js:4658)
at HTMLDivElement.elemData.handle (jquery.js:4478)
create @ submissions.js:33
createItem @ selectize.js:2196
onOptionSelect @ selectize.js:1235
(anonymous) @ selectize.js:687
dispatch @ jquery.js:4658
elemData.handle @ jquery.js:4478


The error is for this portion of code:

create: function(input, callback) {
selectizeCallback = callback;

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,038+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.