ruby acts_as_taggable_on + simple_form + select2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby acts_as_taggable_on + simple_form + select2相关的知识,希望对你有一定的参考价值。
= f.input :tag_list, as: :tags
# in application.coffee
#= require select2
# in application.scss
*= require select2
*= require select2-bootstrap
# in controller
permit(tag_list: [])
class TagsInput < SimpleForm::Inputs::CollectionInput
enable :placeholder
def input(wrapper_options = {})
@collection ||= @builder.object.send(attribute_name)
label_method, value_method = detect_collection_methods
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
merged_input_options.reverse_merge!(multiple: true)
@builder.collection_select(
attribute_name, collection, value_method, label_method,
input_options, merged_input_options
)
end
end
$(document).on 'ready page:load', ->
$('select.form-control.tags').select2({tags: true});
gem 'acts-as-taggable-on'
gem 'simple_form'
gem 'select2-rails'
以上是关于ruby acts_as_taggable_on + simple_form + select2的主要内容,如果未能解决你的问题,请参考以下文章
使用 jquery tokeninput 和acts_as_taggable_on
Rails 4:acts_as_taggable_on 的 text_field 不使用逗号分隔标签
创造性地使用标签
分别显示 Acts_as_taggable 标签
ruby [Ruby Cheat] Cheatsheet #ruby
Ruby运算符