In
one of my recent project, i need to implement a autocomplte in
active_admin interface to select one or more users from user list. I
tried googling on this and zeroed in on the library Chosen. Chosen
by default supports multiple select, selected state.
Include
Chosen gem in your Gemfile.
gem
'chosen-rails'
Once
the gem is installed, include chosen javascript assets to your js
file.
//=
require chosen-jquery
In /app/admin/modelname.rb
ActiveAdmin.register Modlename do#Customize create and edit formformdo|f|f.inputsdof.input :namef.input :othermodel, :input_html => { :class=>"chosen-input"}# other model withhas_manyrelation shipendf.buttonsendend
in active_admin.js
$(document).ready(function(){$(".chosen-input").chosen();});
if you are using coffee script instead of js then use this
$ -># enable chosen js$('.chosen-input').chosenallow_single_deselect: trueno_results_text: 'No results matched'
Then,
include Chosen stylesheet assets to your css file.
Thats it, you will have a nice autocomplte with multiselect . Happy coding...
Thanks for the good post, but does not save data to the database
ReplyDeleteI guess it related to permit_params I am trying this
permit_params :name, :othermodel_ids
but still not working, have you another idea??