using select2 gem with acts_as_taggable gem on rails

感情迁移 提交于 2019-12-08 11:44:30

问题


Im using select2-rails gem in my rails app. I found a problem here:

Problem in tag_list. As u see it starts with ["",...] what wrong. Because of this my tag_list became empty after submitting. Without select2 it works fine. Can any one help?

My erb code

<%= f.label :tag_list, "TAGS" %><br>
<%= f.select :tag_list, options_for_select([['Asst', 'As'], ['Mouse', 'Mm'], ['Yeast', 'Sc']]),{},:multiple => true, :class =>"category" %>

回答1:


There are two problems here: 1) the tag_list parameter is not permitted in your controller and 2)Select2 is returning an array to your controller. To solve this, in your controller permitted params, you should declare the tag_list param like this:

tag_lists: []

It must be in PLURAL.

You should take a look at Rails API regarding strong parameters.



来源:https://stackoverflow.com/questions/31994057/using-select2-gem-with-acts-as-taggable-gem-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!