Rails 4:通过操作邮件程序让 QRCode 显示在电子邮件中 [英] Rails 4: Getting QRCode to display in email via action mailer

查看:81
本文介绍了Rails 4:通过操作邮件程序让 QRCode 显示在电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是让我的 QRCode 显示在通过 Rails 中的 action mailer 发送的电子邮件中.我目前正在使用 gem 'rqrcode_png'
我已经阅读了一些指南,它说明了内联附件.但是,我没有将生成的 QRCode 保存在我自己的文件中.

my problem is to get my QRCode to display in the email sent via action mailer in rails. I am currently using the gem 'rqrcode_png'
I have read through some guides and it states inline attachment. However, I did not save the QRCode generated in my own files.

有没有办法在电子邮件中显示二维码而不必将其保存在我的数据库中?另外,我在我的视图页面上尝试了以下代码并且它有效,但是当我将它复制到我的操作邮件程序代码时它不起作用.它只显示场地二维码.
下面是我用于显示 QRCode 的代码.谢谢!

Is there a way to display the QRCode in the email without having to save it in my database? Also, I have tried the following code on my view page and it works, but it does not work when I copy it to my action mailer code. It only shows the QR Code for venue.
Here is my code below for the displaying of QRCode. Thank you!

<p>
  <% @deal.venues.each do |venue| %>
  <strong>QR Code for <%= venue.neighbourhood %></strong><br>
  <% @qr = RQRCode::QRCode.new(@deal.id.to_s + "_" + venue.id.to_s + "_" + @deal.created_at.to_s).to_img.resize(100, 100).to_data_url %>
  <span><%= image_tag @qr %><br></span>
  <% end %>
</p>

Lewis Buckley 的解决方案,并进行了一些修改

我对代码进行了一些编辑,现在可以正常工作了.因为,我正在使用 ruby​​,我必须将 <%= %> 放在变量周围才能显示它们.

I made some edits to the code and now it is working. As, I am using ruby i have to place <%= %> around the variables in order to display them.

<img src="https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl=<%= @deal.id.to_s + '_' + venue.id.to_s + '_' + @deal.created_at.to_s%>" alt="QR code">

推荐答案

我不确定您的确切用例,但我之前使用过 Google Chart QR 代码生成器,它非常简单(您需要对您的u 方法的内容):

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'.

这篇关于Rails 4:通过操作邮件程序让 QRCode 显示在电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆