我已经将select2与我的活动管理员集成在一起。但是它不能正常工作。它仅显示下拉列表,没有搜索选项。
我点击了以下链接: (Select2-rails is not working with ActiveAdmin)
使用的Ruby版本:ruby-2.6.3 [x86_64] Rails版本:Rails 5.0.7.2
这是我的app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap.min
//= require_tree .
//= require select2
//= require select2_locale_pt-BR
$( "#dropdown" ).select2({
language: "zh-TW"
});
这是我的app/assets/stylesheets/application.css
*= require bootstrap
*= require_tree .
*= require_self
*= require select2
*= require select2-bootstrap
我在这里用过select2,
customer_location.input :area, as: :select2, collection: Region.all.map {|u| [u.area.to_s, u.id]}, :input_html => { :class => 'select2-input', :width => 'auto', "data-placeholder" => 'Select Area' }
答案 0 :(得分:0)
我使用activeadmin-select2 gem
对我来说很好用。
将activeadmin
,jquery-rails
和select2-rails
添加到您的Gemfile中:
gem 'activeadmin'
gem 'jquery-rails'
gem 'select2-rails'
并将activeadmin-select2
添加到您的Gemfile中:
gem 'activeadmin-select2', github: 'mfairburn/activeadmin-select2'
使用以下方法将activeadmin-select2调用添加到active_admin样式表和javascript:
@import "active_admin/select2/base";
#add this line to your app/assets/stylesheets/active_admin.scss
#= require active_admin/select2
#add this line to your app/assets/javascripts/active_admin.js
用法:
过滤器
标准:选择过滤器将自动转换为Select2过滤器。如果您想要多选组合框,请使用:
ActiveAdmin.register Products do
filter :fruits, as: :select2_multiple, collection: [:apples, :bananas, :oranges]
end
选择列表
要使用Select2样式列表,只需将:select更改为:select2或:select2_multiple
ActiveAdmin.register Products do
form do |f|
f.input :fruit, as: :select2
end
form do |f|
f.inputs "Product" do
f.has_many :fruits, allow_destroy: true, new_record: "Add Fruit" do |e|
e.input :fruit, as: :select2_multiple
end
end
end
end