Search code examples
ruby-on-railsrubyqr-code

Ruby-On-Rails qrcode.as_svg doesn't generate images


I have been stuck for the past two days with this. When I try to generate an image of my qr code i get something weird. Doesnt matter what format. For example when I use the "normal" format it works. <%= qrcode = RQRCode::QRCode.new("http://github.com/") %> gives me the expect result.

enter image description here

However when I do: <%= svg = qrcode.as_svg( offset: 0, color: "000", shape_rendering: 'crispEdges', module_size: 6, standalone: true ) %> I get something really weird. I tried importing images through the normal way adding svg files to my assets images file and it works fine enter image description here

Any idea what is going on?

Thanks


Solution

  • You are putting SVG to HTML as text. Use the html_safe method to apply HTML tags from a variable you are inserting.

    <%= qrcode.as_svg( offset: 0, color: "000", shape_rendering: 'crispEdges', module_size: 6, standalone: true ).html_safe %>