在rails中生成QR码 [英] Generating a QR code in rails

查看:167
本文介绍了在rails中生成QR码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在轨道上的ruby中生成QR码,在我用rails编写的网站的后台运行。看到这个 http://code.google.com/p/qrcode-rails/ 但无法弄清楚我怎么能让这个为我工作。基本上在RoR中我想:



将生成器传递给一个字符串,我的唯一代码,一个20个字符长度的数字(例如32032928889998887776),并生成一个名为'的图像' code'_qr.jpg并保存在资源文件夹中,以附加到我的程序将发送的电子邮件中。



我怎么做,有人知道吗? / p>

虽然我问(现在我得到这个答案并不是那么重要)但是我如何实现QR码读入,从网上获取代码凸轮?谢谢。

解决方案

如果你只需要将URL中的数据写入文件,你可以打开一个流,阅读从文件中,只需将数据写入磁盘 - 只需记住使用相同的扩展名(在此实例中为.jpg)。



请注意,您也可以简单地发送电子邮件中的链接(或将其作为电子邮件中的内嵌图像发布。)如果您确实想将其写入磁盘并将其作为附件发送到生产系统中,则Ruby图像处理的一流解决方案是ruby -vips或ImageMagick。



最后,因为它是一个磁盘操作,你会想要在正常的Web请求周期之外完成它 - 你可能是最好的使用delayed_job进行操作,或者至少使用AJAX请求触发进程。这两种方法都可以为您提供操作进度条的优势。


I want to generate QR codes in ruby on rails, to run in the background of my website written in rails. Saw this http://code.google.com/p/qrcode-rails/ but cannot work out how I could get this to work for me. Basically in RoR I want to:

Pass a generator a string, my unique code, a 20 character length number (e.g. 32032928889998887776) and have an image generated with the name 'code'_qr.jpg and saved in a resource folder to be attached to an email that my program will send out.

How would I do this, does anyone know?

And while I'm asking (not so important that I get this answer now) but how would I implement QR code reading in, to get that code back, from a web cam? Thanks.

解决方案

If you just need to write the data from the URL to a file, you can open up a stream, read from the file, and simply write the data to disk -- just remember to use the same extension (.jpg in this instance.)

Note that you could also simply send the link in the email (or post it as an inline image in the email.) If you really, really want to write it to disk and send it as attachment in your production system, the first-class solution for Ruby image processing is ruby-vips or ImageMagick.

Finally, since it's a disk operation, you're going to want to do it outside the normal web request cycle -- you're probably best off farming the operation out with delayed_job, or at the very least triggering the process with an AJAX request. Both of these give you the advantage that you can present a progress bar for the operation.

这篇关于在rails中生成QR码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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