diff options
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 208bf91dd4..7492348c50 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -62,7 +62,7 @@ module ActionView # # <option>3</option><option>4</option></select> # # select_tag "colors", "<option>Red</option><option>Green</option><option>Blue</option>", :multiple => true - # # => <select id="colors" multiple="multiple" name="colors"><option>Red</option> + # # => <select id="colors" multiple="multiple" name="colors[]"><option>Red</option> # # <option>Green</option><option>Blue</option></select> # # select_tag "locations", "<option>Home</option><option selected="selected">Work</option><option>Out</option>" @@ -70,14 +70,15 @@ module ActionView # # <option>Out</option></select> # # select_tag "access", "<option>Read</option><option>Write</option>", :multiple => true, :class => 'form_input' - # # => <select class="form_input" id="access" multiple="multiple" name="access"><option>Read</option> + # # => <select class="form_input" id="access" multiple="multiple" name="access[]"><option>Read</option> # # <option>Write</option></select> # # select_tag "destination", "<option>NYC</option><option>Paris</option><option>Rome</option>", :disabled => true # # => <select disabled="disabled" id="destination" name="destination"><option>NYC</option> # # <option>Paris</option><option>Rome</option></select> def select_tag(name, option_tags = nil, options = {}) - content_tag :select, option_tags, { "name" => name, "id" => name }.update(options.stringify_keys) + html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name + content_tag :select, option_tags, { "name" => html_name, "id" => name }.update(options.stringify_keys) end # Creates a standard text field; use these text fields to input smaller chunks of text like a username |