Last Updated: February 25, 2016
·
6.828K
· smoil

Remote (ajax) multi-select in Rails with Select2

Remote multi-selection using select2 works by placing results into a hidden input field.

When posting to a controller action this will not be converted to an array (Rails only treats multiple inputs with the same id and a little sugar as an array, see: stackoverflow).

To get around this you can define a getter/setter method on your model to handle the array conversion.

This gist includes a light module for accomplishing this and hopefully enough sample code to help you get up to speed.