ActionView::Helpers::UrlHelper
def mail_to(email_address, name = nil, html_options = {}, &block)

Description

Creates an <a> whose href starts with mailto:.

Arguments

Changing a value updates the ERB and HTML.

Used as the part of the href after mailto:. Percent-encodes spaces and punctuation other than @, ., -, _ and ~ (%2B, %20, etc.). If the name argument is omitted, this string is used as the content of the <a>.
= nil
The content of the <a>, escaped. Defaults to the email_address argument. A hash is treated as html_options, so you can leave out this argument and pass only html_options.
html_options= {}
"Hello there"
Adds subject= with the given value after the ? in the href.
"Hi,\nQ&A"
Adds body= with the given value after the ? in the href.
"cc@example.com"
Adds cc= with the given value after the ? in the href.
"bcc@example.com"
Adds bcc= with the given value after the ? in the href.
"reply@example.com"
Adds reply-to= with the given value after the ? in the href. reply-to is the key with _ changed to -. A string "reply-to" key becomes an HTML attribute of the <a> as is.
"https://example.com"
Ignored. The href is always the mailto: URL built from the email_address argument.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <a>, and ones this site considers rarely used, are not listed here.

Shared by all helpers

{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{controller: "tags", tags_suggestions_value: ["ruby", "rails"]}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
Any other html_options become HTML attributes of the <a>; those with a nil value are left out. Unlike link_to, method and remote also become HTML attributes as is.

The five options such as subject are added to the href as follows:

  • They are joined with &, in the order cc → bcc → body → subject → reply-to, regardless of the order given.
  • @, spaces, line breaks, &, etc. in the values are percent-encoded (%40, %20, %0A, %26).
  • An array is converted to a string (["a@example.com", "b@example.com"]) and added.
  • An empty string or nil value is left out.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview