Forum: Ruby on Rails Help with Create and Update with options_for_select in a sel

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-25 01:01
(Received via mailing list)
I have a  select_tag in my view that uses options_for_select with
multiple = true. I am having trouble figuring out the Rails way to
create and update that field. Please help.

Service has_many AccessControl
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 />

#create works but is this the best way?
def create
if params[:access_control]
        params[:access_control].each do |value|
        control =
        control.value = value
        control.service_id =
        @service.access_controls << control

def update
  ??? I have no idea how to update the access_controls fields

Thanks in advance, K
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2007-05-25 01:48
(Received via mailing list)
Hey Kim, what you can do:


<select name="parties[]" multiple size="3" >
    <% for party in @parties %>
          <option value="<%= %>"><%= %></option>
     <% end %>

The Rails Way:

select( "party", "id", Party.find(:all).collect {|p| [, ]
}, { :multiple => true, :size => 3 } )

Good luck,

8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-05-25 02:03
(Received via mailing list)
Hi Conrad,
Thanks, but no, that will not work.

 select( "party", "id", Party.find(:all).collect {|p| [, ]}, { :multiple => true, :size => 3 } )

select can not do a multiple select. Yes you can put :multiple => true
in it, and in the UI it will look like it is multi-selecting things,
but it actual does not send more then one thing in the params hash.
Disagree? Prove me wrong.

I have seen plenty of code examples for doing this when the options
are coming from a database (just like your example), but if you look
at my post, you will see that I do not have that case. I have a hash
of static options, not options from a database.

Thanks anyways.

Any other ideas? K
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-05-25 21:15
(Received via mailing list)
I have not been able to find any examples. Anyone know how to do this?
This topic is locked and can not be replied to.