aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb11
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb19
3 files changed, 28 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 8d391fc169..024bbf52f2 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -7,7 +7,7 @@
<% end %>
Will output:
- <div class="strong"><p>Hello world!</p></div>
+ <div class="strong">Hello world!</div>
* Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => true #6409 [BobSilva]
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 5bfa1eefca..8d6d8e99ea 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -17,7 +17,7 @@ module ActionView
# * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post".
# If "put", "delete", or another verb is used, a hidden input with name _method
# is added to simulate the verb over post.
- def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)
+ def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
html_options = options.stringify_keys
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
html_options["action"] = url_for(url_for_options, *parameters_for_url)
@@ -34,7 +34,14 @@ module ActionView
method_tag = tag(:input, :type => "hidden", :name => "_method", :value => method)
end
- tag(:form, html_options, true) + method_tag
+ if block_given?
+ content = capture(&block)
+ concat(tag(:form, html_options, true) + method_tag, block.binding)
+ concat(content, block.binding)
+ concat("</form>", block.binding)
+ else
+ tag(:form, html_options, true) + method_tag
+ end
end
alias_method :start_form_tag, :form_tag
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 743d75ca8c..cfc95a5a08 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -1,10 +1,11 @@
require File.dirname(__FILE__) + '/../abstract_unit'
class FormTagHelperTest < Test::Unit::TestCase
-
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper
+ include ActionView::Helpers::TextHelper
+ include ActionView::Helpers::CaptureHelper
def setup
@controller = Class.new do
@@ -39,6 +40,22 @@ class FormTagHelperTest < Test::Unit::TestCase
assert_dom_equal expected, actual
end
+ def test_form_tag_with_block
+ _erbout = ''
+ form_tag("http://example.com") { _erbout.concat "Hello world!" }
+
+ expected = %(<form action="http://www.example.com" method="post">Hello world!</form>)
+ assert_dom_equal expected, _erbout
+ end
+
+ def test_form_tag_with_block_and_method
+ _erbout = ''
+ form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" }
+
+ expected = %(<form action="http://www.example.com" method="post"><input type="hidden" name="_method" value="put" />Hello world!</form>)
+ assert_dom_equal expected, _erbout
+ end
+
def test_hidden_field_tag
actual = hidden_field_tag "id", 3
expected = %(<input id="id" name="id" type="hidden" value="3" />)