Skip to content
Browse files

Made FormTagHelper#form_tag work with blocks, rendering start/end_for…

…m_tag deprecated

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5345 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 6c06205 commit e407b44ba14e5ab72f25ca107291e7a4d51051b8 @dhh dhh committed Oct 23, 2006
View
2 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]
View
11 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -17,7 +17,7 @@ module FormTagHelper
# * <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 @@ def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)
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
View
19 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 @@ def test_form_tag_with_method
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" />)

0 comments on commit e407b44

Please sign in to comment.
Something went wrong with that request. Please try again.