0

I would like to offer an easy interface for selecting information based on the hierarchy of the information.

In my example the user needs to enter his county.

A county is placed in a state and a state is part of a country. So this is my rails model:

# Country
class Country < ActiveRecord::Base
  has_many :states
end

# State
class State < ActiveRecord::Base
  belongs_to :country
  has_many :counties
end

# County
class County < ActiveRecord::Base
  belongs_to :state
end

So in my user interface the user should first select the country, based on the country selection the list of associated states is presented and based on the selected state the list of counties is presented.

Is it possible to create this behaviour with ActiveAdmin

PascalTurbo
  • 2,189
  • 3
  • 24
  • 41
  • You probably want to look at http://stackoverflow.com/questions/8080479/multistep-form-with-activeadmin or https://github.com/activeadmin/activeadmin/issues/3279 I think it would be not possible with ActiveAdmin out of the box and you should implement the behaviour your way. – baxang Mar 18 '15 at 06:17
  • Instead of using nested attributes I flattened my model and use autocomplete boxes with activeadmin_associations – PascalTurbo Mar 26 '15 at 08:25

1 Answers1

0

ActiveAdmin Addons gem provides option to integrate nested select in ActiveAdmin

example page

  • With ajax request
f.input :county_id, as: :nested_select,
                  level_1: {
                    attribute: :country_id,
                    url: '/api/countries'
                  },
                  level_2: {
                    attribute: :state_id,
                    url: '/api/states'
                  },
                  level_3: {
                    attribute: :county_id,
                    url: '/api/counties'
                  }
  • with preloaded collections
f.input :county_id, as: :nested_select,
                  level_1: {
                    attribute: :country_id,
                    collection: Country.all
                  },
                  level_2: {
                    attribute: :state_id,
                    collection: State.all
                  },
                  level_3: {
                    attribute: :county_id,
                    collection: County.all
                  }
Sampat Badhe
  • 8,710
  • 7
  • 33
  • 49