Skip to content

Commit

Permalink
Patch #mail_to helper to work in Ruby 2.0
Browse files Browse the repository at this point in the history
See rails/rails#21402 for details.
  • Loading branch information
mvz committed Sep 15, 2015
1 parent a7c35fb commit d04b83f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class Application < Rails::Application

require 'publify_login_system'

require 'active_support_patch'

Date::DATE_FORMATS.merge!(
:long_weekday => '%a %B %e, %Y %H:%M'
)
Expand Down
24 changes: 24 additions & 0 deletions lib/active_support_patch.rb
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

0 comments on commit d04b83f

Please sign in to comment.