Hi! I have categories and subcategories. Now I want to create a select tag with this data so a user can select either a category or a subcategory. What I tried first was to use grouped_collection_select and use the main categories as groups and list the subcategories inside. Visually, this is the goal. The problem with this is that I need to be able to select the main categories as well and not only the subcategories. So, now I want to list them like this: <select> <option data-foo="abc">Cat1</option> <option data-foo="das">-- Subcat1</option> <option data-foo="fsd">-- Subcat2</option> <option data-foo="asda">Cat2</option> <option data-foo="das">-- Subcat...</option> .... How can I implement this? I''ve tried using the collection_select() method but I don''t get it right. @menu_categories contains the main categories and the subcategories are in some_category.subcategories Any help is very appreciated. Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/dlJuYSu5U1EJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Linus Pettersson wrote in post #1065179:> Hi! > > I have categories and subcategories. Now I want to create a select tag > with > this data so a user can select either a category or a subcategory. What > I > tried first was to use grouped_collection_select and use the main > categories as groups and list the subcategories inside. Visually, this > is > the goal. The problem with this is that I need to be able to select the > main categories as well and not only the subcategories. > > So, now I want to list them like this: > <select> > <option data-foo="abc">Cat1</option> > <option data-foo="das">-- Subcat1</option> > <option data-foo="fsd">-- Subcat2</option> > <option data-foo="asda">Cat2</option> > <option data-foo="das">-- Subcat...</option> > .... > > How can I implement this? I''ve tried using the collection_select() > method > but I don''t get it right. >Have you tried "option_groups_from_collection_for_select"? http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-option_groups_from_collection_for_select -- Posted via http://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No...but that''s generating the same as grouped_collection_select() but without the wrapping <select> tag so that doesn''t work... Den tisdagen den 19:e juni 2012 kl. 19:55:43 UTC+2 skrev Ruby-Forum.com User:> > Linus Pettersson wrote in post #1065179: > > Hi! > > > > I have categories and subcategories. Now I want to create a select tag > > with > > this data so a user can select either a category or a subcategory. What > > I > > tried first was to use grouped_collection_select and use the main > > categories as groups and list the subcategories inside. Visually, this > > is > > the goal. The problem with this is that I need to be able to select the > > main categories as well and not only the subcategories. > > > > So, now I want to list them like this: > > <select> > > <option data-foo="abc">Cat1</option> > > <option data-foo="das">-- Subcat1</option> > > <option data-foo="fsd">-- Subcat2</option> > > <option data-foo="asda">Cat2</option> > > <option data-foo="das">-- Subcat...</option> > > .... > > > > How can I implement this? I''ve tried using the collection_select() > > method > > but I don''t get it right. > > > > Have you tried "option_groups_from_collection_for_select"? > > > http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-option_groups_from_collection_for_select > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/4L22aV1zdtoJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.