select2-rails + act_as_taggable_on rails 4 issue

后端 未结 1 1259
醉酒成梦
醉酒成梦 2021-01-29 03:16

I installed select2-rails and act_as_taggable_on gem to my app. I setup the act_as_taggable_on and it works (I tested from the console). However, when I tried to create the view

相关标签:
1条回答
  • 2021-01-29 03:42

    It's working now. I did it with this code: https://stackoverflow.com/a/33035355/5081949

    Here is my code now:

    app/views/profiles/new.html.erb

    <%= f.input :skill_list, input_html: { class: 'multiple-input', multiple: "multiple" }, collection: @profile.skill_list %>
    

    app/assets/application.js

    $(document).ready(function() {
      $('.multiple-input').each(function() {
        $(this).select2({
          tags: true,
          tokenSeparators: [','],
          theme: 'bootstrap',
          placeholder: 'Separated by comma'
          });
        });
    });
    

    also in apps/controllers/profiles_controller.rb I added strong params

    def profile_params
      params.require(:profile).permit(:name, skill_list: [])
    end
    
    0 讨论(0)
提交回复
热议问题