Rails 4: Getting QRCode to display in email via action mailer

房东的猫 提交于 2019-12-07 03:26:25

I'm not sure about your exact use case but I have used the Google Chart QR code generator before and it is super simple (you need to url encode your content with the u method):

<img src="https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl=#{u(@deal.id.to_s + "_" + venue.id.to_s + "_" + @deal.created_at.to_s)}&amp;choe=UTF-8" alt="QR code">

And then just copy that into your mailer 'view'.

Define @url in the controller.  Here's examples to linkto for debugging and the img source for displaying.  The above example used url encoding for &amp; and this didn't work for me.  Use & for the urls.

<%= link_to("https://chart.googleapis.com/chart?chs=545x545&cht=qr&chl=#{@url}&choe=UTF-8","https://chart.googleapis.com/chart?chs=545x545&cht=qr&chl=#{@url}&choe=UTF-8") %>

<img src="https://chart.googleapis.com/chart?chs=545x545&;cht=qr&;chl=#{@url}&;choe=UTF-8" alt="QR code"> 

chs=548x547 is the max allowed for size, which you'll need for larger urls.  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!