method
option_groups_from_collection_for_select
v1.0.0 -
Show latest stable
- Class:
ActionView::Helpers::FormOptionsHelper
option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil)public
Returns a string of option tags, like options_from_collection_for_select, but surrounds them with <optgroup> tags.
An array of group objects are passed. Each group should return an array of options when calling group_method Each group should return its name when calling group_label_method.
html_option_groups_from_collection(@continents, "countries", "continent_name", "country_id", "country_name", @selected_country.id)
Could become:
<optgroup label="Africa"> <select>Egypt</select> <select>Rwanda</select> ... </optgroup> <optgroup label="Asia"> <select>China</select> <select>India</select> <select>Japan</select> ... </optgroup>
with objects of the following classes: class Continent
def initialize(p_name, p_countries) @continent_name = p_name; @countries = p_countries; end def continent_name() @continent_name; end def countries() @countries; end
end class Country
def initialize(id, name) @id = id; @name = name end def country_id() @id; end def country_name() @name; end
end
NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.