Barby 无法生成一些二维码 - nil.rszf

发布于 2024-09-25 03:09:24 字数 2669 浏览 6 评论 0原文

在IRB中

<块引用>

数据=“2 1058 657682” 条形码 = Barby::QrCode.new(数据) File.open('条形码.png', 'w+') {|f| f.write Barcode.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”)它工作正常。

宝石:

巴比 0.4.0 png 1.1.0(1.2.0 不断出现 String::CompilationError)

In irb

data = "2 1058 657682"
barcode = Barby::QrCode.new(data)
File.open('barcode.png', 'w+')
{|f| f.write barcode.to_png(:height => 100, :margin => 25, :xdim => 100) }

Generates error:

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'
...

Whereas if I change data to "2 1058 657681" (replace the final '2' for a '1') it works fine.

Gems:

barby 0.4.0
png 1.1.0 (1.2.0 kept getting String::CompilationError)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半山落雨半山空 2024-10-02 03:09:24

在 barby-/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb 的第 295 行,更改

if byte_index < data.size

if byte_index < data.size && ! data[byte_index].nil?

Have fun!

In line 295 of barby-<version>/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb, change

if byte_index < data.size

into

if byte_index < data.size && ! data[byte_index].nil?

Have fun!

洒一地阳光 2024-10-02 03:09:24

尝试使用 Barby 0.4.2,但也失败了。问题出在 RQRCode 库中,该库仍处于 0.3.2 版本。

您可以尝试传递 :size 参数来覆盖动态计算的参数,但最终会在不同的字符串上失败。

我发现绕过该问题的唯一方法是尝试一个级别,如果失败则尝试另一个级别。

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

在一个级别中生成的错误在另一个级别中没有发生......很奇怪但有效。

Tried with Barby 0.4.2 and it fails as well. The problem is in the RQRCode library which is still in version 0.3.2.

You can try and pass a :size parameter to override the dinamically calculated one but it will eventually fail on a different string.

The only way I found to bypass the problem was to try in one level and try another if it fails.

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

An error generated in one level did not occur in another.. wierd but works.

柠檬 2024-10-02 03:09:24

干杯!看起来 rqrcode 和 Barby 都已更新以修复此错误。
toretore/barby

Cheers! Looks like rqrcode and in turn Barby have been updated to fix this bug.
toretore/barby

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文