Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的“二维”方法&x27;使用Barby CairoOutputter_Ruby On Rails_Ruby_Ruby On Rails 4_Cairo - Fatal编程技术网

Ruby on rails 未定义的“二维”方法&x27;使用Barby CairoOutputter

Ruby on rails 未定义的“二维”方法&x27;使用Barby CairoOutputter,ruby-on-rails,ruby,ruby-on-rails-4,cairo,Ruby On Rails,Ruby,Ruby On Rails 4,Cairo,我只想用rqrcodegem生成一个QR码。创建新的rqrcode实例时: qr = RQRCode::QRCode.new('test') 我得到以下输入: 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

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

qr = RQRCode::QRCode.new('test')
我得到以下输入:

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_码,我使用了Barby的CairoOutputter,但当我尝试将输出转换为svg、png,。。。我收到以下错误消息:

NoMethodError (undefined method `two_dimensional?' for #<RQRCode::QRCode:0x0000000794bd88>)
在我的模型中:

require 'barby'
require 'barby/outputter/cairo_outputter'
require 'rqrcode'
qr = RQRCode::QRCode.new('test')
puts  qr
outputter = Barby::CairoOutputter.new(qr).to_svg
如中所述,您需要使用受支持的
条码
类之一。也就是说,您需要使用
Barby::QrCode
,而不是
RQRCode::QrCode

已安装以下库:

gem install 'barby'   # core library
gem install 'cairo'   # dependency for output
gem install 'rqrcode' # dependency for barcode
以下实施效果良好:

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\u dimensional?
encoding
等方法,这是
Barby::CairoOutputter
实现所需的。

outputter=Barby::CairoOutputter.new(qr)。您能否提供一个完整、最少、可验证的示例?这可能是库中的一个bug,最好直接在github项目中作为一个问题提出…qr=RQRCode::QRCode.new('test')将qr outputter=Barby::CairoOutputter.new(qr)。要解决这个问题吗
Barby::CairoOutputter.new(qr.to_s).to_svg
感谢您的回答,但当我将qr实例转换为字符串时,我收到以下错误消息:未定义的方法“二维”,因为我也尝试过,但qr实例的输出是“test”。所以我的svg是一个白色的图像。。。
require 'barby'
require 'barby/outputter/cairo_outputter'
require 'barby/barcode/qr_code'

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