简体   繁体   中英

Rails: Multi-select box syntax

Basically I have this form:

<%= builder.select(:song_id, options_for_select(@selections.sort!), {}, {multiple: true, size: 7}) %>

Which in the html is rendering something like this:

<input name="allocation[song_id][]" type="hidden" value="" />
<select id="allocation_song_id" multiple="multiple" name="allocation[song_id][]" size="7">

Basically I'm curious as to where the second set of array brackets (allocation[song_id]**[]**) comes from, as I think it's affecting the way my arguments are passing (the song id keeps defaulting to the first song upon form submission). Any pointers would be much appreciated.

Multiple select box is like checkbox. If you can select more than one option, then it should be array (brackets are array). Hidden input is when no one is selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM