简体   繁体   English

Rails和HAML:Mailto与图片链接

[英]Rails and HAML: Mailto link with picture

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. 我正在尝试创建一个mailto链接,其中涉及单击图片,并将一些原始内容从文本文件包含到邮件正文中。

The following doesn't work (haml). 以下无效(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. 我知道有一个:body声明,但是在此上下文中它的使用使我难以理解。

Thoughts? 有什么想法吗?

The mail_to helper only appears to accept a block in Rails 4 , not previous versions . 在Rails 4中mail_to帮助器似乎只接受一个阻止 ,而不是以前的版本 If you're using Rails 3 and can't upgrade, you could do something like this: 如果您使用的是Rails 3并且无法升级,则可以执行以下操作:

- 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: 要获取正文内容,您只需要使用:body键将options哈希作为最后一个参数传递给mail_to

Rails 4: Rails 4:

= mail_to "friend@example.com", :body => "Body text here" do
  %img{:src=>asset_path('mail.png')} 

Rails 3: Rails 3:

=mail_to "friend@example.com", mail_link_content, :body => "Body text here"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM