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 %>
*</
span>Access Control:
<%=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 %>
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