首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义方法`two_dimensional?‘使用Barby CairoOutputter

未定义方法`two_dimensional?‘使用Barby CairoOutputter
EN

Stack Overflow用户
提问于 2017-06-07 09:20:49
回答 1查看 219关注 0票数 2

我只想使用rqrcode gem生成一个QR代码。当我创建新的rqrcode实例时:

代码语言:javascript
复制
qr = RQRCode::QRCode.new('test')

我得到以下输入:

代码语言:javascript
复制
xxxxxxx  x  x x  xxxxxx x xxxxxxx
x     x xx xxxxx     xx   x     x
x xxx x   x   x xxxx  xx  x xxx x
x xxx x   x x x x  x x xx x xxx x
x xxx x  x   xxx xxx    x x xxx x
x     x xxx  x    xx      x     x
xxxxxxx x x x x x x x x x xxxxxxx
        x x     xx   x x         
    xxxx  xxxxx  xxxx   x xx   x 
 x  xx xxxx   xxxx xxxx    x  xxx
xx x xx   x x  xxxx            xx
  x  x x  xxx xxxxxxx x xx xxx  x
x  xxxxxxx x x x xxxx xx xx  xx  
x x x         xx xxx x  x xxxx   
xx   xxx  xxx xxx   x  xxxxx xxx 
xx   x   xx     xxx   xx  x   x  
   x  xxxx xx    xxxx x x  x  x x
 x xxx  x x x   xx  x    xx  xx x
xxx  xx xx     x   x xx     xx   
     x x x        x xx  xx xx  x 
x  xxxx xx xx  x  x x  xxxx    xx
x x x      xxx x     xx   xxx xxx
    x xx  x xxx  x       x x   xx
    xx   x xxx xxxx x x x    x  x
xx x xxxx xx   x    x xxxxxxxxx  
        x  xx xx x x   xx   xx  x
xxxxxxx xx x        xxxxx x xxx  
x     x xx xx   x xxxx xx   x xx 
x xxx x xx  x     xxx   xxxxx xxx
x xxx x    xx  x     xxxxxxxx xxx
x xxx x   x xx        xx    x    
x     x   xxxxxxxxx x xx xx xx   
xxxxxxx  x xx  x xx    x x x xx x

为了打印我的qr_code,我使用了Barby的CairoOutputter,但是当我试图将输出转换为svg,png,.我收到以下错误消息:

代码语言:javascript
复制
NoMethodError (undefined method `two_dimensional?' for #<RQRCode::QRCode:0x0000000794bd88>)

你对我能做些什么来纠正这个错误有什么想法吗?

Gemfile:

代码语言:javascript
复制
gem 'rqrcode','~> 0.4.2'
gem 'barby'
gem 'cairo'

在我的模型中:

代码语言:javascript
复制
require 'barby'
require 'barby/outputter/cairo_outputter'
require 'rqrcode'
qr = RQRCode::QRCode.new('test')
puts  qr
outputter = Barby::CairoOutputter.new(qr).to_svg
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-07 10:27:32

正如README中所述,您需要使用一个受支持的barcode类。也就是说,您需要使用Barby::QrCode,而不是RQRCode::QRCode

安装了以下库:

代码语言:javascript
复制
gem install 'barby'   # core library
gem install 'cairo'   # dependency for output
gem install 'rqrcode' # dependency for barcode

以下实现工作正常:

代码语言:javascript
复制
require 'barby'
require 'barby/outputter/cairo_outputter'
require 'barby/barcode/qr_code'

qr = Barby::QrCode.new('test')
outputter = Barby::CairoOutputter.new(qr).to_svg

RQRCode::QRCode不同,Barby::QrCode实现了two_dimensional?encoding等方法--这是Barby::CairoOutputter实现所必需的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44408548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档