Rails 5 ask_as_taggable with select2

前端 未结 1 1041
孤街浪徒
孤街浪徒 2021-01-23 16:21

I cannot see the effect of select2 in rails 5 form whether it\'s a text_field or select. does anyone know why the tag_list is not being populated. I can see that the tag_list ha

1条回答
  •  醉梦人生
    2021-01-23 16:46

    I solved it by changing text-field to select:

    <%= f.select(:tag_list, Tag.all.order(:name).collect { |a| [a.name, a.id]}, {}, id: "tag_list", label:'Tags', :multiple => true)%>
    

    JS code is:

    $(function() {
    $("#tag_list" ).select2();
    

    });

    and yes, do add a file called Tag.rb in app/models. The gem only installs tables but doesn't create model.

    class Tag < ApplicationRecord
       validates_presence_of :name
    end
    

    0 讨论(0)
提交回复
热议问题