Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How Do I Use Selectize in Rails 6

Gems / Libraries • Asked by Jeremy Bray

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

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.