Rails通过select2(和simple_form)作为可标记的行为 [英] Rails acts-as-taggable-on with select2 (and simple_form)

查看:62
本文介绍了Rails通过select2(和simple_form)作为可标记的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个select2下拉标签,我可以在其中选择多个现有标签并添加新标签.

I would like to have a select2 dropdown of tags, where i could select multiple existing tags and add new ones.

我尝试了许多不同的方法,或者要么没有select2框正常工作,要么仅传递了一个值(最后一个).

I have tried many different ways and i either don't get select2 box working or only one value is passed (last one).

这是我得到的最接近的值(通过了最后一个值):

This is closest i got (passes last value):

<%= f.input :tag_list, collection: @model.tags.map { |t| t.name }, input_html: { :style=> 'width: 300px', class: "taggable", data: { placeholder: "Tags" }} %>

推荐答案

如前所述,普通的select2库现在仅使用选择输入类型,但是在使用select2-full库时,它确实适用于输入类型.

As I mentioned before, normal select2 library now uses only select input types, but it does work with input types when using select2-full library.

所以,这是解决一个问题的方法.

So, this was a way out of one problem.

仍然我仅传递一个单一值存在问题. 我实际上是从其中一个示例复制/粘贴代码,这是错误的. 有人说,强参数应该包括:tag_list,这很明显,但是实际上必须使用{tag_list []}才能接受所有值.

Still I had problems with only passing one single value. I was actually copy/pasting code from one of the examples and it was wrong. It was stated that strong parameters should include :tag_list, which is obvious, but it is actually {tag_list[]} that was needed in order to accept all the values.

现在就像魅力一样.

这篇关于Rails通过select2(和simple_form)作为可标记的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆