Rails after selecting from a select dropdown, populate a list based on that selection?

I'm trying to build a view that will first present a user with a select dropdown. In this dropdown will be a few available model types (e.g. car, boat, bike).

When a user makes a selection, I then would like to have a list below that populate with all the instances of that model so that the user can select some of the objects.

As an example, if a user selected boat, they would see a list of all the available boats, and could select multiple of them.

I have the select working, but I'm having trouble figuring out how to do the list portion.

Some of the ways I believe I could do it include:

  • Use another select with :multiple => true that is populated with options whenever the first select has an item selected
  • Populate a table with the options when a selection is made and have each row in this table have a check box to allow selecting of items

Is there some other (better) way to do this, or am is my best bet using one of the two options above? Additionally, is the best way to populate the list/multi-select/table (whenever the first selection is made) to make an Ajax call to my controller and then populate based on the returned results like is detailed in this post?

1 answer

  • answered 2018-01-11 20:59 Michael Arkhipov

    1. Check good article on this subject without js/ajax stuff.
    2. Or you can also use gem for multi-steps forms, for example wicked.