In one of my recent project, I need to implement an autocomplete in active_admin interface to select one or more users from the user list. I tried googling on this and zeroed in on the library Chosen.Chosen by default supports multiple select, selected state.Chosen is available as a gem for Ruby on Rails which fits well with Asset Pipeline.
Include Chosen gem in your Gemfile.
1
gem ‘chosen-rails’
Once the gem is installed, include chosen javascript assets to your js file.
1
//= require chosen-jquery
In /app/admin/modelname.rb
12345678910
ActiveAdmin.register Modlename do
#Customize creates and edit form
form do |f|
f.inputs do
f.input :name
f.input :othermodel, :input_html => { :class => "chosen-input" } # other model with has_many relation ship
end
f.buttons
end
end
Then, include Chosen stylesheet assets to your css file.
1
*= require chosen
To include more details check Here
Thats it, you will have a nice autocomplte with multiselect . Happy coding…
Comments
Lobna Mohamed
Thanks for the good post, but does not save data to the database I guess it related to permit_params I am trying this permit_params :name, :othermodel_ids but still not working, have you another idea??
I guess it related to permit_params I am trying this
permit_params :name, :othermodel_ids
but still not working, have you another idea??