diff options
author | George Claghorn <george.claghorn@gmail.com> | 2017-12-29 20:15:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-29 20:15:26 -0500 |
commit | 35e9638daffd0f844ee072418fcd73472aa283ec (patch) | |
tree | c83d760563449fafaed78d841fcdaacb221195a5 /actionview/lib/action_view | |
parent | 6bd465e1bff36c541a992731922f967985ad0eeb (diff) | |
parent | 0d73056436329c21aa0cca972964e8df49670391 (diff) | |
download | rails-35e9638daffd0f844ee072418fcd73472aa283ec.tar.gz rails-35e9638daffd0f844ee072418fcd73472aa283ec.tar.bz2 rails-35e9638daffd0f844ee072418fcd73472aa283ec.zip |
Merge pull request #31578 from Aquaj/feature/allow-callables-in-select-group-methods
Allow the use of callable objects as group methods for grouped selects.
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r-- | actionview/lib/action_view/helpers/form_options_helper.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index 02a44477c1..a46741f661 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -214,9 +214,15 @@ module ActionView # * +method+ - The attribute of +object+ corresponding to the select tag # * +collection+ - An array of objects representing the <tt><optgroup></tt> tags. # * +group_method+ - The name of a method which, when called on a member of +collection+, returns an - # array of child objects representing the <tt><option></tt> tags. + # array of child objects representing the <tt><option></tt> tags. It can also be any object that responds + # to +call+, such as a +proc+, that will be called for each member of the +collection+ to retrieve the + # value. + # * +group_label_method+ - The name of a method which, when called on a member of +collection+, returns a - # string to be used as the +label+ attribute for its <tt><optgroup></tt> tag. + # string to be used as the +label+ attribute for its <tt><optgroup></tt> tag. It can also be any object + # that responds to +call+, such as a +proc+, that will be called for each member of the +collection+ to + # retrieve the label. + # * +option_key_method+ - The name of a method which, when called on a child object of a member of # +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag. # * +option_value_method+ - The name of a method which, when called on a child object of a member of @@ -457,9 +463,9 @@ module ActionView def option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil) collection.map do |group| option_tags = options_from_collection_for_select( - group.send(group_method), option_key_method, option_value_method, selected_key) + value_for_collection(group, group_method), option_key_method, option_value_method, selected_key) - content_tag("optgroup".freeze, option_tags, label: group.send(group_label_method)) + content_tag("optgroup".freeze, option_tags, label: value_for_collection(group, group_label_method)) end.join.html_safe end |