aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/url_helper.rb
diff options
context:
space:
mode:
authorSam Pohlenz <sam@sampohlenz.com>2013-04-03 14:42:48 +1030
committerSam Pohlenz <sam@sampohlenz.com>2013-04-03 14:42:48 +1030
commit4bb26dd7b298b08f53c7e157ddc19dc7febcf37e (patch)
tree2715daf3f3bd8ae32e51555e467a43412a9f28af /actionpack/lib/action_view/helpers/url_helper.rb
parent37683266d86db2b7c39cb32a1e39e3698f6a93a8 (diff)
downloadrails-4bb26dd7b298b08f53c7e157ddc19dc7febcf37e.tar.gz
rails-4bb26dd7b298b08f53c7e157ddc19dc7febcf37e.tar.bz2
rails-4bb26dd7b298b08f53c7e157ddc19dc7febcf37e.zip
Add block support for the helper
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 775d93ed39..a1468b6e90 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -439,18 +439,29 @@ module ActionView
# mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
# subject: "This is an example email"
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
- def mail_to(email_address, name = nil, html_options = {})
- email_address = ERB::Util.html_escape(email_address)
-
+ #
+ # You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
+ #
+ # <%= mail_to "me@domain.com" do %>
+ # <strong>Email me:</strong> <span>me@domain.com</span>
+ # <% end %>
+ # # => <a href="mailto:me@domain.com">
+ # <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.stringify_keys!
+ email_address = ERB::Util.html_escape(email_address)
+
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)
+
+ content_tag(:a, name || email_address.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block)
end
# True if the current request URI was generated by the given +options+.