提交 8b1ccd59 编写于 作者: C Carlos Antonio da Silva

Simplify handling of defaults/options in button_tag

There's no need to rely on Active Support's Hash#reverse_merge for
simple cases with default values, since we can just merge from the
default rather than reverse merge from the options.

This also avoids the creation of one extra hash object by moving to a
Hash#merge! call.
上级 ecda6dfb
......@@ -469,16 +469,13 @@ def submit_tag(value = "Save changes", options = {})
# # => <button data-disable-with="Please wait..." name="button" type="submit">Checkout</button>
#
def button_tag(content_or_options = nil, options = nil, &block)
default_options = { 'name' => 'button', 'type' => 'submit' }
if content_or_options.is_a? Hash
options = content_or_options
else
options ||= {}
end
options = options.stringify_keys
options = options.reverse_merge default_options
options = { 'name' => 'button', 'type' => 'submit' }.merge!(options.stringify_keys)
if block_given?
content_tag :button, options, &block
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册