How to make optgroup with rails version 3

20 views
Skip to first unread message

Bernardo Carrasco

unread,
Apr 24, 2014, 4:18:55 PM4/24/14
to rubyonra...@googlegroups.com

I am trying to set up a drop down list with a optgroup with active users. i know the following code is wrong, but would there be any way of doing this how i have it? right now if you take the raw section and just have data.collect {|a| [ a.name, a.id ] } instead, it works great for just showing the names of the users, but i want to add that optgorup. How would i go about doing that?

= f.select "#{available_filter_option.col_names}", [raw("<optgroup label='Active Users'><option> " + data.collect {|a| [ a.name, a.id ] } + " </option></optgroup>")],
                    {:include_blank => ' '}, class: 'closed_filters', filter: available_filter_option.col_names, :filter_type => 'select_box'

Thank you in advance guys.


Walter Lee Davis

unread,
Apr 25, 2014, 7:14:01 AM4/25/14
to rubyonra...@googlegroups.com
I'm assuming you tried the grouped_collection_select helper for creating a picker with opt groups, and found that you could not control the order of the opt groups in the list, right? I just hit this a few months ago, and couldn't find any way out of it except hand-coding the outer select and letting the options_for_select picker build the inner parts. Otherwise, the opt groups came out in alphabetical order, and nothing could change that.

If you haven't tried that yet, then start here for some docs: http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/grouped_collection_select

Walter


>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/237b2172-bbf8-4dd1-b347-f095e58f38c8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages