Skip to content

Commit e2f998a

Browse files
Support mail_to options when name not specified
When `name` is not specified, `mail_to` uses `email_address` as the link text. This commit allows options to be specified in such a case.
1 parent 1fcd1e4 commit e2f998a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

actionview/lib/action_view/helpers/url_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ def link_to_if(condition, name, options = {}, html_options = {}, &block)
468468
# mail_to "me@domain.com", "My email"
469469
# # => <a href="mailto:me@domain.com">My email</a>
470470
#
471-
# mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
471+
# mail_to "me@domain.com", cc: "ccaddress@domain.com",
472472
# subject: "This is an example email"
473-
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
473+
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">me@domain.com</a>
474474
#
475475
# You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
476476
#
@@ -481,7 +481,7 @@ def link_to_if(condition, name, options = {}, html_options = {}, &block)
481481
# <strong>Email me:</strong> <span>me@domain.com</span>
482482
# </a>
483483
def mail_to(email_address, name = nil, html_options = {}, &block)
484-
html_options, name = name, nil if block_given?
484+
html_options, name = name, nil if name.is_a?(Hash)
485485
html_options = (html_options || {}).stringify_keys
486486

487487
extras = %w{ cc bcc body subject reply_to }.map! { |item|

actionview/test/template/url_helper_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ def test_mail_to_with_options
705705
mail_to("me@example.com", "My email", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message.", reply_to: "foo@bar.com")
706706
)
707707

708+
assert_dom_equal(
709+
%{<a href="mailto:me@example.com?cc=ccaddress%40example.com&amp;bcc=bccaddress%40example.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email&amp;reply-to=foo%40bar.com">me@example.com</a>},
710+
mail_to("me@example.com", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message.", reply_to: "foo@bar.com")
711+
)
712+
708713
assert_dom_equal(
709714
%{<a href="mailto:me@example.com?body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email">My email</a>},
710715
mail_to("me@example.com", "My email", cc: "", bcc: "", subject: "This is an example email", body: "This is the body of the message.")

0 commit comments

Comments
 (0)