Forum: Ruby on Rails How do I show the selected values in options_for_select? Not

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-05-24 23:18
(Received via mailing list)
How do I show the selected values in options_for_select? I have a
Service model and a AccessControl model. When a user edits a Service I
want the services access_controls to be pre-selected.

Service has_many AccessControls
AccessControl belongs_to Service

$types = Array["Athens", "htpasswd", "IP",   "None",  "Other",
"Password", "Shibboleth"]

% if @service.access_controls
    @types = @service.access_controls.collect{|a| a.value}.join(' ')
end %>
<label for="access_control_value"><span class = "required">*</
span>Access Control:</label>
<%=select_tag 'access_control[]',
    options_for_select($types,   @types), {:multiple => true, :size =>
5, :id => "access_control_value",
    :onfocus=>"fixedtooltip(CONTROL_MSSG, this, event,
'')", :onblur=>"delayhidetip()"}%>
<%= error_message_on :service, :access_controls %><br />

But when I edit a Service with access_controls, nothing is pre-
selected. What am I doing wrong?

Please, show me in this example, not some simple example that I have
seen a million times already, i.e., the API example.

Thanks in advance, K
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-05-25 00:06
(Received via mailing list)
Solved it myself:

need to change
@types = @service.access_controls.collect{|a| a.value}.join(' ')


@types = @service.access_controls.collect{|a| a.value}
This topic is locked and can not be replied to.