Permalink
Browse files

accept a block in button helper.

  • Loading branch information...
yuki24 committed Jun 4, 2012
1 parent 2186540 commit 0ec88cd1c83bdd66d06c2b475e0ace6c41be475e
Showing with 18 additions and 3 deletions.
  1. +13 −2 actionpack/lib/action_view/helpers/form_helper.rb
  2. +5 −1 actionpack/test/template/form_helper_test.rb
@@ -1311,10 +1311,21 @@ def submit(value=nil, options={})
# post:
# create: "Add %{model}"
#
- def button(value=nil, options={})
+ # ==== Examples
+ # button("Create a post")
+ # # => <button name='button' type='submit'>Create post</button>
+ #
+ # button do
+ # content_tag(:strong, 'Ask me!')
+ # end
+ # # => <button name='button' type='submit'>
+ # # <strong>Ask me!</strong>
+ # # </button>
+ #
+ def button(value = nil, options = {}, &block)
value, options = nil, value if value.is_a?(Hash)
value ||= submit_default_value
- @template.button_tag(value, options)
+ @template.button_tag(value, options, &block)
end
def emitted_hidden_id?
@@ -1054,6 +1054,9 @@ def test_form_for
concat f.check_box(:secret)
concat f.submit('Create post')
concat f.button('Create post')
+ concat f.button {
+ concat content_tag(:span, 'Create post')
+ }
end
expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch') do
@@ -1063,7 +1066,8 @@ def test_form_for
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
"<input name='commit' type='submit' value='Create post' />" +
- "<button name='button' type='submit'>Create post</button>"
+ "<button name='button' type='submit'>Create post</button>" +
+ "<button name='button' type='submit'><span>Create post</span></button>"
end
assert_dom_equal expected, output_buffer

0 comments on commit 0ec88cd

Please sign in to comment.