Ruby-On-Rails qrcode.as_svg 不生成图像

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

过去两天我一直被这个问题困扰着。当我尝试生成我的二维码图像时,我得到了一些奇怪的东西。不管什么格式。例如,当我使用 "normal" 格式时它起作用了。 <%= qrcode = RQRCode::QRCode.new("http://github.com/") %> gives me the expect result.

enter image description here

但是当我这样做时: <%= svg = qrcode.as_svg( offset: 0, color: "000", shape_rendering: 'crispEdges', module_size: 6, standalone: true ) %> 我得到一些非常奇怪的东西。我尝试通过正常方式导入图像,将 svg 文件添加到我的资产图像文件中,它工作正常 enter image description here

知道发生了什么吗?

谢谢

您可以尝试使用 html_safe,因为您将 svg 作为文本插入到 html,但我不确定,因为您提供的信息不多)

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

或者

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

如果您想调用任何助手,您也可以使用:

:ruby
  @qrcode = RQRCode::QRCode.new(url: 'www.google.es').as_svg


= raw @qrcode.html_safe

对我来说看起来干净多了。