From 797fcdf738a2a2772544731027d4fc5ca9d358bc Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 4 Apr 2013 21:29:50 -0300 Subject: Refactor mail_to to not generate intermediate hashes when adding href There's no need to use Hash#merge with a new hash just for setting the href option to pass it through. Since we're always dealing with a new html_options hash, we're free to just set the value instead. --- actionpack/lib/action_view/helpers/url_helper.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_view/helpers/url_helper.rb') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index bfe11fc1d7..22059a0170 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -449,19 +449,20 @@ module ActionView # Email me: me@domain.com # def mail_to(email_address, name = nil, html_options = {}, &block) - html_options, name = name, nil if block_given? - html_options ||= {} - html_options = html_options.stringify_keys - email_address = ERB::Util.html_escape(email_address) + html_options, name = name, nil if block_given? + html_options = (html_options || {}).stringify_keys + extras = %w{ cc bcc body subject }.map { |item| option = html_options.delete(item) || next "#{item}=#{Rack::Utils.escape_path(option)}" }.compact extras = extras.empty? ? '' : '?' + ERB::Util.html_escape(extras.join('&')) - content_tag(:a, name || email_address.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block) + html_options["href"] = "mailto:#{email_address}#{extras}".html_safe + + content_tag(:a, name || email_address.html_safe, html_options, &block) end # True if the current request URI was generated by the given +options+. -- cgit v1.2.3