En mi proyecto Ruby on Rails (6.1), instalé con éxito acts-as-taggable-on (funciona desde la consola y con entradas manuales feas), ahora estoy tratando de agregarle selectize.js. Vi esto aquí , pero no estoy seguro de cómo se supone que funciona. EDITAR: solucioné el problema inicial de que no podía ejecutar el código Ruby en JS, así que ahora tengo un .js.erb, y cambié la pregunta en consecuencia.
Puedo:
No puedo:
Aquí está el código del formulario:
<%= form.text_field :tag_list, as: :string, class: "p-1 font-size-m mb-1 selectize-tags", id: 'tag-select' %>y aquí está el 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, }; }, });