How do I show the selected values in options_for_select? Not as simple as it sounds.

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.

Models: Service has_many AccessControls AccessControl belongs_to Service

application.rb: $types = Array["Athens", "htpasswd", "IP", "None", "Other", "Password", "Shibboleth"]

View: % if @service.access_controls     @types = @service.access_controls.collect{|a| a.value}.join(' ') end %> <label for="access_control_value"><span class = "required">*</

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

Solved it myself:

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

to

@types = @service.access_controls.collect{|a| a.value}