在嘗試在 HTML 中呈現文章條形碼集合并逐步查看資料(相對于頁面上的其他物件)時,控制器
require 'barby/outputter/html_outputter'
require 'barby/barcode/ean_13'
并且視圖呼叫
<%= this_barcode = article.barcodes.first.barcode %>
<%= this_barcode.class %>
<%# barcode = Barby::EAN13.new(this_barcode) %>
<%# outputter = Barby::HtmlOutputter.new(barcode) %>
<%# barcode.to_html.html_safe %>
[returns as expected]
8001300303466 String
但是,當想要獲取條形碼并取消注釋該元素時,它無法處理,因為data not valid對于該行barcode = Barby::EAN13.new(this_barcode)(也與 一起出現barcode = Barby::EAN13.new(this_barcode.to_i))
注意可能在此處的花園路徑上,因為與wiki 建議的內容 存在混淆,因為
barcode = Barby::DataMatrix.new(number)這會產生錯誤
uninitialized constant Barby::DataMatrix
如何確保資料正確以進行正確渲染?
uj5u.com熱心網友回復:
這是問題所在:
8001300303466有 13 個字符。這是正確的條形碼。
我假設一個人可以提交正確的條形碼。但是gem 的 ean_13.rb 檔案的第 54 行
允許 12 個字符的資料元素FORMAT = /^\d{12}$/并繼續計算校驗位。
因此,
<%= barcode = Barby::EAN13.new(this_barcode[0...-1]) %>
最終將正確處理資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474206.html
