-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch #mail_to helper to work in Ruby 2.0
See rails/rails#21402 for details.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ActionView | ||
module Helpers | ||
module UrlHelper | ||
# Monkey-patch mail_to to work on Ruby 2.0. | ||
# See https://github.com/rails/rails/pull/21402 | ||
# TODO: Remove once this is part of a Rails release. | ||
def mail_to(email_address, name = nil, html_options = {}, &block) | ||
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? ? '' : '?' + extras.join('&') | ||
|
||
encoded_email_address = ERB::Util.url_encode(email_address.to_str).gsub("%40", "@") | ||
html_options["href"] = "mailto:#{encoded_email_address}#{extras}" | ||
|
||
content_tag(:a, name || email_address, html_options, &block) | ||
end | ||
end | ||
end | ||
end |