Multiple select listboxes in Rails

Since I think the documentation is lacking and I always have to rely on Stackoverflow every time I want to use it, I keep this a remind-me-note:

 

<%= f.select :user,
    options_from_collection_for_select(
      User.all,   # The object list
      "id",       # get this attribute as key
      "email",    # SHow this in listbox
      @store.store_admins.ids
    ),
    {}, #html attributes, empty here
    {
      :size => 5, 
      :multiple=>true
    } # "select" options
%>

Now we can all wonder why this simple example isnt in the documentation…….

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.