Ruby on rails 如何修复rqrcode gem的“未定义方法'as_png'”
当我尝试使用gem将二维码转换为PNG文件时,我遇到了这个错误:Ruby on rails 如何修复rqrcode gem的“未定义方法'as_png'”,ruby-on-rails,ruby,qr-code,Ruby On Rails,Ruby,Qr Code,当我尝试使用gem将二维码转换为PNG文件时,我遇到了这个错误: undefined method `as_png' for #<RQRCodeCore::QRCode:0x00007f90b42ec330> 还有 有什么想法吗?我不知道为什么要初始化RGRCodeCore::QRCode,而不是dinjas指出的RQRCode::QRCode。尝试按照文档建议的方式进行更改: require 'rqrcode' self.secure_hex = SecureRandom.hex
undefined method `as_png' for #<RQRCodeCore::QRCode:0x00007f90b42ec330>
还有
有什么想法吗?我不知道为什么要初始化RGRCodeCore::QRCode,而不是dinjas指出的RQRCode::QRCode。尝试按照文档建议的方式进行更改:
require 'rqrcode'
self.secure_hex = SecureRandom.hex
self.qr_code = RQRCode::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}")
self.qr_code_image = RQRCode::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}").as_png
另外,在共享的代码中,您创建了self.qr\u代码的实例,该实例包含与self.qr\u代码图像实例相同的字符串。你确定需要吗?我不熟悉这个gem,但是你链接的API文档是针对RQRCode::QRCode的,你正在初始化一个RQRCodeCore::QRCode就是这样!非常感谢。就这样!谢谢大家!@杰克逊里索我很高兴!接受答案
require 'rqrcode'
self.secure_hex = SecureRandom.hex
self.qr_code = RQRCode::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}")
self.qr_code_image = RQRCode::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}").as_png