views:

62

answers:

1

Hi Guys. 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.

A: 

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.

Joe
Thanks for the quick answer. I'm quite new to rails and so I understand that that creates the QR code in the html output but I'm unsure how to save that to an image?
Ive actually found something quite interesting:
Ah, well you'll want to do that with some other task. Since it's a disk operation, you're probably best off farming the operation out with delayed_job or at the very least with an AJAX request. Are you currently seeing the QR codes on your page?
Joe
Well, first note that you could just send the link in the email (or post it as an inline image in the email.) If you really want to write it to disk and send it as attachment -- the first-class solution for Ruby image processing is ruby-vips or ImageMagick. But note that 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.)
Joe
Any luck......?
Joe