diff options
author | José Valim <jose.valim@gmail.com> | 2012-06-05 01:20:43 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-06-05 01:20:43 -0700 |
commit | 76830e110a73d6db0dafd42fc960686637cbfc7b (patch) | |
tree | 0b99ab7793fb54836a3375033ae94f80788a42ff | |
parent | fedb0e27a42172a89441d4dea8816eb8e794dad4 (diff) | |
parent | 0ec88cd1c83bdd66d06c2b475e0ace6c41be475e (diff) | |
download | rails-76830e110a73d6db0dafd42fc960686637cbfc7b.tar.gz rails-76830e110a73d6db0dafd42fc960686637cbfc7b.tar.bz2 rails-76830e110a73d6db0dafd42fc960686637cbfc7b.zip |
Merge pull request #6631 from yuki24/use_block_in_button_helper
Accept a block in FormHelper#button
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 15 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 6 |
2 files changed, 18 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ac150882b1..7dd35f7357 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1311,10 +1311,21 @@ module ActionView # 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? diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index c9b39ed18f..b3e0c0256a 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1054,6 +1054,9 @@ class FormHelperTest < ActionView::TestCase 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 @@ class FormHelperTest < ActionView::TestCase "<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 |