Is there any rails QR code plugin for Rails 3?
I want to generate QR code for my application which is going to run in Rails 3.0, Is there any plugin available for that ?
Thanks in Advance, J开发者_如何学Pythonak.
You can use Google's Chart API
def generate_qr_image( url )
raw "http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=#{url}&choe=UTF-8"
end
I think Google changed the api end point.
This worked for me:
= image_tag "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=#{url}&choe=UTF-8"
As I understand it, anything based on google charts is deprecated, so not a long term solution.
I've used both the rqrcode gem and one of the many javascript encoders.
I Agree with TrAvid but it won't work, just need a small minute change,
Just assign @url="www.google.com"
in the controller and then use this @url
in View as
<%= image_tag "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=#{@url}&choe=UTF-8" %>
It worked for me great.
I use the rqrcode_png that allow you to save the code as an image or do it like a table. It also let you display the image without saving it.
Here is an example of how save the image
qr = RQRCode::QRCode.new( 'your string', :size => 1, :level => :h )
image = qr.to_img.resize(250,250)
image.save('name.png')
or if you don't want to save it you can
qr = RQRCode::QRCode.new( 'your string', :size => 1, :level => :h )
@png = qr.to_img.resize(250,250).to_data_url
and then in your view <%= image_tag @png %>
精彩评论