ActiveAdmin plugin for one-to-many / many-to-many / many-to-one associations
An Active Admin plugin which improves one-to-many / many-to-many / many-to-one associations selection using 2 new inputs: select_many and select_one (jQuery required).
Features for select_many:
Features for select_one:
(inspired by RailsAdmin associations selector)
gem 'activeadmin_select_many'
@import 'activeadmin/select_many';
//= require activeadmin/select_many
as: :select_many
in Active Admin model confAdd to ActiveAdmin model config, in form block.
f.input :sections, as: :select_many
f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json )
f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json ), search_param: 'category_contains', member_label: 'category', placeholder: 'Type something...'
f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json ), sortable: true
Example to update position field:
after_save :on_after_save
controller do
def on_after_save( object )
if params[:article][:section_ids]
order = {}
params[:article][:section_ids].each_with_index { |id, i| order[id.to_i] = i }
object.sections.each { |item| item.update_column( :position, order[item.id].to_i ) }
end
end
end
Example to enable JSON response on an ActiveAdmin model:
ActiveAdmin.register Tag do
config.per_page = 30 # to limit served items
config.sort_order = 'name_asc'
index download_links: [:json]
end
In a form:
f.input :article, as: :select_one, placeholder: 'Search...', remote_collection: admin_articles_path( format: :json ), search_param: 'title_contains', member_label: 'title'
As filter:
filter :article_id_eq, as: :select_one, filter_form: true, placeholder: 'Search...', search_param: 'title_contains', member_label: 'title', remote_collection: '/admin/articles.json'
If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other Active Admin components.
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: about me.