Kim
2007-May-24 21:16 UTC
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">*</
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Kim
2007-May-24 22:06 UTC
Re: How do I show the selected values in options_for_select? Not as simple as it sounds.
Solved it myself:
need to change
@types = @service.access_controls.collect{|a| a.value}.join(''
'')
to
@types = @service.access_controls.collect{|a| a.value}
On May 24, 2:16 pm, Kim
<Kim.Gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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">*</
> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---