diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-23 23:30:36 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-23 23:30:36 +0000 |
commit | e407b44ba14e5ab72f25ca107291e7a4d51051b8 (patch) | |
tree | 0c4a6ff856a4d42d8e0f8c779cd01659946fca38 | |
parent | 6c062054cdb236fead5d09679985ebb70d8b053a (diff) | |
download | rails-e407b44ba14e5ab72f25ca107291e7a4d51051b8.tar.gz rails-e407b44ba14e5ab72f25ca107291e7a4d51051b8.tar.bz2 rails-e407b44ba14e5ab72f25ca107291e7a4d51051b8.zip |
Made FormTagHelper#form_tag work with blocks, rendering start/end_form_tag deprecated
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5345 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 11 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 19 |
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" />) |