# How do I show the selected values in options\_for\_select? Not

**URL:** <https://www.ruby-forum.com/t/how-do-i-show-the-selected-values-in-options-for-select-not/105016>\
**Category:** Rails\
**Created:** [May 24, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/how-do-i-show-the-selected-values-in-options-for-select-not/105016 "2007-05-24T23:18:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [May 24, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/how-do-i-show-the-selected-values-in-options-for-select-not/105016/1 "2007-05-24T23:18:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [May 25, 2007, 12:06am UTC](https://www.ruby-forum.com/t/how-do-i-show-the-selected-values-in-options-for-select-not/105016/2 "2007-05-25T00:06:31Z")

</div>

Solved it myself:

need to change  
@types = @service.access\_controls.collect{|a| a.value}.join(’ ')

to

@types = @service.access\_controls.collect{|a| a.value}
