Browse files

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.
  • Loading branch information...
1 parent e936cf9 commit 797fcdf738a2a2772544731027d4fc5ca9d358bc @carlosantoniodasilva carlosantoniodasilva committed Apr 4, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 actionpack/lib/action_view/helpers/url_helper.rb
View
11 actionpack/lib/action_view/helpers/url_helper.rb
@@ -449,19 +449,20 @@ def link_to_if(condition, name, options = {}, html_options = {}, &block)
# <strong>Email me:</strong> <span>me@domain.com</span>
# </a>
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+.

0 comments on commit 797fcdf

Please sign in to comment.