Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
Rails: acts-as-taggable-on and selectize

In my Ruby on Rails project (6.1), I have successfully installed acts-as-taggable-on (works from console and with ugly manual inputs), now I am trying to add selectize.js to it. I saw this here, but not sure how it is supposed to work. EDIT: I fixed the initial problem that I couldn't execute ruby code in JS - so now I have a .js.erb, an I changed the question accordingly.

I can:

  • successfully add ONE tag
  • successfully REMOVE a tag

I cannot:

  • properly display all tags in the form if there are multiple tags - the form shows as empty, and if I then select another tag (or create a new one) - everything is replaced by the one new tag (which kind of is consistent)... HOWEVER, when I check the entry BEFORE redisplaying the form - in a console for example - everything is ok, the proper tags ARE associated with that entry (I can do entry.tags and all is fine - one or more tags, as expected, are being displayed)
  • display new tags in the drop down. I THINK the problem is that the tags for the drop down are collected in the js.erb file - and that is not run / compiled every time a new tag is added...?

Here's the code from the form:

<%= form.text_field :tag_list, as: :string, class: "p-1 font-size-m mb-1 selectize-tags", id: 'tag-select' %>

and here is the JS (.js.erb):

 <%= all_tags = ActsAsTaggableOn::Tag.all.uniq.pluck(:id, :name) %>
  $(".selectize-tags").selectize({
    delimiter: ",",
    persist: true,
    allowEmptyOption: false,
    options: [
      <% all_tags.each do |t| %>
        {text: '<%=t[1] %>', value: '<%=t[1]%>' },
      <% end %>
    ],
    sortField: "text",
    create: function (input) {
      return {
        value: input,
        text: input,
      };
    },
  });
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda