diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-03-09 06:48:04 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-03-09 06:48:04 -0800 |
commit | 3a210da65f7718721f86397d64e43beb534121ef (patch) | |
tree | 05c83df0f6b9081a29ad5ab6927275edb181b9e8 /actionpack | |
parent | 01c891824e30861a0f6884f15cbe5fc929b90f5f (diff) | |
parent | 8e05a6f6380c6ddbef5a0620b30d19dbca7f2f15 (diff) | |
download | rails-3a210da65f7718721f86397d64e43beb534121ef.tar.gz rails-3a210da65f7718721f86397d64e43beb534121ef.tar.bz2 rails-3a210da65f7718721f86397d64e43beb534121ef.zip |
Merge pull request #9616 from exviva/multiple_select_name_double_square_brackets
Fix incorrectly appended square brackets to a multiple select box
Before:
select(:category, [], {}, {:multiple => true, :name => "post[category][]"})
# => <select name="post[category][][]" ...>
After:
select(:category, [], {}, {:multiple => true, :name => "post[category][]"})
# => <select name="post[category][]" ...>
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 15 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/base.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 8 |
3 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 1050626884..f757911c23 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,20 @@ ## Rails 4.0.0 (unreleased) ## +* Fix incorrectly appended square brackets to a multiple select box + if an explicit name has been given and it already ends with "[]" + + Before: + + select(:category, [], {}, multiple: true, name: "post[category][]") + # => <select name="post[category][][]" ...> + + After: + + select(:category, [], {}, multiple: true, name: "post[category][]") + # => <select name="post[category][]" ...> + + *Olek Janiszewski* + * Fixed regression when using `assert_template` to verify files sent using `render file: 'README.md'`. Fixes #9464. diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb index 3d597079c4..aef1572290 100644 --- a/actionpack/lib/action_view/helpers/tags/base.rb +++ b/actionpack/lib/action_view/helpers/tags/base.rb @@ -84,7 +84,7 @@ module ActionView options["id"] = options.fetch("id"){ tag_id } end - options["name"] += "[]" if options["multiple"] + options["name"] += "[]" if options["multiple"] && !options["name"].ends_with?("[]") options["id"] = [options.delete('namespace'), options["id"]].compact.join("_").presence end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 04cdd068c8..29d63d9653 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -575,6 +575,14 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_multiple_and_with_explicit_name_ending_with_brackets + output_buffer = select(:post, :category, [], {include_hidden: false}, multiple: true, name: 'post[category][]') + assert_dom_equal( + "<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>", + output_buffer + ) + end + def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input output_buffer = select(:post, :category, "", {}, :multiple => true, :disabled => true) assert_dom_equal( |