From 829de9d98e59f9b083ed96a9031cd9841c83ae47 Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Sat, 12 Feb 2011 12:07:47 +0000 Subject: Add block support to button_tag helper As per the HTML 4.01 spec: Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content. For example, a BUTTON element that contains an image functions like and may resemble an INPUT element whose type is set to "image", but the BUTTON element type allows content. Since rich content is the main purpose of the # - # button_tag "Ask me!", :type => 'button' + # button_tag(:type => 'button') do + # content_tag(:strong, 'Ask me!') + # end # # => @@ -442,7 +445,9 @@ module ActionView # # => # - def button_tag(label = "Button", options = {}) + def button_tag(content_or_options = nil, options = nil, &block) + options = content_or_options if block_given? && content_or_options.is_a?(Hash) + options ||= {} options.stringify_keys! if disable_with = options.delete("disable_with") @@ -455,7 +460,7 @@ module ActionView options.reverse_merge! 'name' => 'button', 'type' => 'submit' - content_tag :button, label, { "type" => options.delete("type") }.update(options) + content_tag :button, content_or_options || 'Button', options, &block end # Displays an image which when clicked will submit the form. -- cgit v1.2.3