I am trying to create a mailto link that involves clicking a picture and including some raw content from a text file into the body of the message.
The following doesn't work (haml).
= mail_to "friend@example.com" do
%img{:src=>"#{asset_path 'mail.png'}"}
I don't even know how I'd get the body preloaded in there. I know there is a :body
declaration but its usage in this context eludes me.
Thoughts?
The mail_to
helper only appears to accept a block in Rails 4, not previous versions. If you're using Rails 3 and can’t upgrade, you could do something like this:
- mail_link_content = capture_haml do
%img{:src=>asset_path('mail.png')}
=mail_to "friend@example.com", mail_link_content
Note that you don’t need to use a string if the contents are all interpolated (you might need to add parentheses though).
To get the body content, you just need to pass an options hash as the last argument to mail_to
with a :body
key:
Rails 4:
= mail_to "friend@example.com", :body => "Body text here" do
%img{:src=>asset_path('mail.png')}
Rails 3:
=mail_to "friend@example.com", mail_link_content, :body => "Body text here"