Created
September 12, 2013 19:32
-
-
Save aamax/6542698 to your computer and use it in GitHub Desktop.
Rails: multi select control with multiple items pre selected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def edit | |
@publication = Publication.find(params[:id]) | |
@recipients = @publication.users | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ???? 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