首页 > 解决方案 > Ruby-On-Rails qrcode.as_svg 不生成图像

问题描述

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

在此处输入图像描述

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

知道发生了什么吗?

谢谢

标签: ruby-on-railsrubyqr-code

解决方案


您可以尝试使用 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 %>

推荐阅读