diff options
Diffstat (limited to 'actionview')
| -rw-r--r-- | actionview/CHANGELOG.md | 12 | ||||
| -rw-r--r-- | actionview/lib/action_view/helpers/form_options_helper.rb | 6 | ||||
| -rw-r--r-- | actionview/lib/action_view/helpers/url_helper.rb | 4 | ||||
| -rw-r--r-- | actionview/test/template/digestor_test.rb | 4 | ||||
| -rw-r--r-- | actionview/test/template/form_options_helper_test.rb | 10 |
5 files changed, 30 insertions, 6 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index c5bb8fe627..fe8bbde445 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,13 @@ +* Element of the `grouped_options_for_select` can + optionally contain html attributes as the last element of the array. + + Example: + grouped_options_for_select( + [["North America", [['United States','US'],"Canada"], :data => { :foo => 'bar' }]] + ) + + *Vasiliy Ermolovich* + * Fix default rendered format problem when calling `render` without :content_type option. It should return :html. Fix #11393. @@ -13,7 +23,7 @@ After: link_to(action: 'bar', controller: 'foo') { content_tag(:span, 'Example site') } - # => "<a href=\"/\"><span>Example site</span></a>" + # => "<a href=\"/foo/bar\"><span>Example site</span></a>" *Murahashi Sanemat Kenichi* diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index 4e9ef94ff3..8351548f06 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -520,12 +520,16 @@ module ActionView end grouped_options.each do |container| + html_attributes = option_html_attributes(container) + if divider label = divider else label, container = container end - body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), :label => label) + + html_attributes = { :label => label }.merge(html_attributes) + body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), html_attributes) end body diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index daa9a393b3..a4f04b0b3b 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -16,7 +16,7 @@ module ActionView # provided here will only work in the context of a request # (link_to_unless_current, for instance), which must be provided # as a method called #request on the context. - + BUTTON_TAG_METHOD_VERBS = %w{patch put delete} extend ActiveSupport::Concern include TagHelper @@ -289,7 +289,7 @@ module ActionView remote = html_options.delete('remote') method = html_options.delete('method').to_s - method_tag = %w{patch put delete}.include?(method) ? method_tag(method) : ''.html_safe + method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : ''.html_safe form_method = method == 'get' ? 'get' : 'post' form_options = html_options.delete('form') || {} diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 07f8d36d93..67e3775f28 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -100,7 +100,7 @@ class TemplateDigestorTest < ActionView::TestCase assert_not_nil digest("level/recursion") # assert digest is stored end - def test_chaning_the_top_templete_on_recursion + def test_chaining_the_top_template_on_recursion assert digest("level/recursion") # assert recursion is possible assert_digest_difference("level/recursion") do @@ -110,7 +110,7 @@ class TemplateDigestorTest < ActionView::TestCase assert_not_nil digest("level/recursion") # assert digest is stored end - def test_chaning_the_partial_templete_on_recursion + def test_chaining_the_partial_template_on_recursion assert digest("level/recursion") # assert recursion is possible assert_digest_difference("level/recursion") do diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index 8c90a58a84..3ec138b639 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -302,6 +302,16 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_grouped_options_for_select_with_array_and_html_attributes + assert_dom_equal( + "<optgroup label=\"North America\" data-foo=\"bar\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\" disabled=\"disabled\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>", + grouped_options_for_select([ + ["North America", [['United States','US'],"Canada"], :data => { :foo => 'bar' }], + ["Europe", [["Great Britain","GB"], "Germany"], :disabled => 'disabled'] + ]) + ) + end + def test_grouped_options_for_select_with_optional_divider assert_dom_equal( "<optgroup label=\"----------\"><option value=\"US\">US</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"----------\"><option value=\"GB\">GB</option>\n<option value=\"Germany\">Germany</option></optgroup>", |
