提交 76830e11 编写于 作者: J José Valim

Merge pull request #6631 from yuki24/use_block_in_button_helper

Accept a block in FormHelper#button
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册