Select-2 with active admin in rails | Ram Laxman Yadav

Select-2 with active admin in rails

Hello There!!, In the previous blog we lean how to deploy a rails application with passenger and nginx. Today we are going to learn how to deploy a rails application with passenger and nginx with SSL. Here is an example of that

Install Gem

Add gem 'activeadmin-select2', github: 'mfairburn/activeadmin-select2' in your application’s Gemfile and run bundle install.

Using in resource form

You can use select-2 as two different purpose. as like:

Single select option

Write following line inside the form section of resource(active admin model)

form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs 'Details' do
      f.input :attribute_name, as: :select2, collection: OPTIONS_FOR_SELECT, label: 'Your placeholders', :input_html => {YOUR_CUSTOM_STYLES(optional)}
    end
    f.actions
  end

Multiple selection

Write following line inside the form section of resource(active admin model)

form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs 'Details' do
      f.input :attribute_name, as: :select2_multiple, collection: OPTIONS_FOR_SELECT, label: 'Your placeholders', :input_html => {YOUR_CUSTOM_STYLES(optional)}
    end
    f.actions
  end

Now You can see both single and multiple use of select-2 in active admin rails. Thanks for the reading !!!!!!

Ram Laxman Yadav
Ram Laxman Yadav
Ruby on Rails Developer