Skip to content

Instantly share code, notes, and snippets.

@aamax
Created September 12, 2013 19:32
Show Gist options
  • Save aamax/6542698 to your computer and use it in GitHub Desktop.
Save aamax/6542698 to your computer and use it in GitHub Desktop.
Rails: multi select control with multiple items pre selected
def edit
@publication = Publication.find(params[:id])
@recipients = @publication.users
end
# ???? is there a way to duplicate this behavior with a rails helper?
# --------------------------------------------------------------------
<select id='recipients_id' multiple='multiple' name='recipients[id][]'>
<% User.all.each do |u| %>
<option value='<%= u.id %>'
<%= @recipients.include?(u) ? "selected='selected'" : '' %> ><%= u.name %></option>
<% end %>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment