1

irbで

data = "21058657682"バーコード=Barby:: QrCode.new(data)File.open('barcode.png'、'w +'){| f | f.writebarcode.to_png(:height => 100、:margin => 25、:xdim => 100)}

エラーを生成します:

ActionView::TemplateError (/Library/Ruby/Gems/1.8/gems/barby-    0.4.0/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:296:in `map_data': You have a nil     object when you didn't expect it!
The error occurred while evaluating nil.rszf) on line <a href="/toretore/barby/issues/#issue/1" class="internal">#1</a> of app/views/profile/ticket.rpdf:
1: pdf.font_families["Helvetica"] =
2: {
3:   "b"   => "Helvetica-Bold",
4:   "i"   => "Helvetica-Oblique"    
lib/pdf_render.rb:46:in `pdf'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:291:in `each'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:291:in `map_data'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:287:in `step'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:287:in `map_data'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:172:in `make_impl'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:196:in `get_best_mask_pattern'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:195:in `each'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:195:in `get_best_mask_pattern'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:145:in `make'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:85:in `initialize'
barby (0.4.0) lib/barby/barcode/qr_code.rb:94:in `new'
barby (0.4.0) lib/barby/barcode/qr_code.rb:94:in `rqrcode'
barby (0.4.0) lib/barby/barcode/qr_code.rb:55:in `encoding'
barby (0.4.0) lib/barby/outputter.rb:86:in `encoding'
barby (0.4.0) lib/barby/outputter/png_outputter.rb:67:in `height'
barby (0.4.0) lib/barby/outputter.rb:116:in `send'
barby (0.4.0) lib/barby/outputter.rb:116:in `with_options'
barby (0.4.0) lib/barby/outputter.rb:114:in `each'
barby (0.4.0) lib/barby/outputter.rb:114:in `inject'
barby (0.4.0) lib/barby/outputter.rb:114:in `with_options'
barby (0.4.0) lib/barby/outputter/png_outputter.rb:18:in `to_canvas'
barby (0.4.0) lib/barby/outputter/png_outputter.rb:58:in `to_png'
barby (0.4.0) lib/barby/barcode.rb:70:in `send'
barby (0.4.0) lib/barby/barcode.rb:70:in `method_missing'
(eval):107:in `pdf'
(eval):88:in `each'
(eval):88:in `pdf'
lib/pdf_render.rb:18:in `eval'
lib/pdf_render.rb:46:in `pdf'
lib/pdf_render.rb:18:in `render'
...

一方、データを「2 1058 657681」に変更すると(最後の「2」を「1」に置き換えます)、正常に機能します。

宝石:

barby 0.4.0 png 1.1.0(1.2.0はString :: CompilationErrorを取得し続けました)

4

3 に答える 3

2

barby-<version>/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb の 295 行目で、

if byte_index &lt; data.size

の中へ

if byte_index &lt; data.size &amp;&amp; ! data[byte_index].nil?

楽しむ!

于 2011-01-31T21:10:29.570 に答える
0

Barby 0.4.2 で試してみましたが、同様に失敗します。問題は、まだバージョン 0.3.2 の RQRCode ライブラリにあります。

:size パラメーターを渡して動的に計算されたパラメーターをオーバーライドすることはできますが、最終的には別の文字列で失敗します。

問題を回避する唯一の方法は、あるレベルで試して、失敗した場合は別のレベルを試すことでした。

begin
  student_barcode = Barby::QrCode.new(content, :level => :q)
rescue NoMethodError
  student_barcode = Barby::QrCode.new(content, :level => :m)
end

あるレベルで発生したエラーは、別のレベルでは発生しませんでした..奇妙ですが動作します。

于 2010-11-01T22:53:28.480 に答える
0

乾杯!rqrcode のように見え、Barby が更新されてこのバグが修正されました。 とれとれバービー

于 2011-02-08T09:18:30.337 に答える