On Apr 27, 10:52 am, Jim Burgess <rails-mailing-l...@andreas-s.net>
wrote:
> Hi,
>
> I'm trying to produce a select menu with "optgroup" tags.
> The HTML output should look like this:
>
>  <optgroup label="Europe">
>     <option value="Denmark">Denmark</option>
>     <option value="Germany">Germany</option>
>     <option value="France">France</option>
>   </optgroup>
>   <optgroup label="North America">
>     <option value="US">United States</option>
>     <option value="Canada">Canada</option>
>   </optgroup>
>
> In rails I'm typing this:
>
> <%= f.select :member_1,
> grouped_options_for_select ([['North America',[['United
> States','US'],'Canada']],
> ['Europe',['Denmark','Germany','France']]]) %>

select is not expecting a chunk of html, it's expecting something like
[['option label', option_value], ...]

you might want to use either select_tag (which is expecting a blob of
html)

Fred


>
> The result is that rails is adding the generated HTML to the select
> menu, that is to say that in the generated menu, instead of seeing:
>
> Europe
>  Denmark
>  France
>
> etc ..
>
> I see
> <optgroup label="Europe"><option value="Denmark">Denmark</option>
>
> etc..
>
> (See attachment)
>
> Here is the HTML produced by Rails:
> <select id="applicant_member_1" name="applicant[member_1]">
> <option value="&lt;optgroup label=&quot;North America&quot;&gt;
> &lt;option value=&quot;US&quot;&gt;United States&lt;/option&gt;">
> &lt;optgroup label=&quot;North America&quot;&gt;&lt;
> option value=&quot;US&quot;&gt;United States&lt;/option&gt;
> </option>
> ....
>
> Can anyone help me to sort this out?
> What am I doing wrong?
> How do I properly create a menu with optgroup labels?
>
> Thanks in advance for your help
>
> Attachments:http://www.ruby-forum.com/attachment/3624/menu.jpg
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to