【问题标题】:Barcode not showing on rails [Barby Gem]条码未显示在导轨上 [Barby Gem]
【发布时间】:2018-12-26 00:30:53
【问题描述】:

使用的宝石

Ruby '1.9.3'

Rails '3.2.11'

Bbarby', '~> 0.5.1'

Chunky_png', '~> 1.3.0'

应用程序助手

require 'barby'
require 'barby/barcode/code_128'
require 'barby/barcode/ean_13'
require 'barby/outputter/png_outputter'
require 'barby/outputter/ascii_outputter'

require 'chunky_png'

控制器

barcode = Barby::Code128B.new('The noise of mankind has become too much')

File.open('code128b.png', 'w'){|f|
f.write barcode.to_png(:height => 20, :margin => 5)
}

查看

<%= image_tag("code128b.png") %>

页面呈现但不呈现条形码:

【问题讨论】:

    标签: ruby-on-rails ruby png barcode


    【解决方案1】:

    【讨论】:

    • 嗨 Vinod,我已经安装了 gem 'barby', '~> 0.5.1' AND gem 'chunky_png', '~> 1.3.0'。我还需要安装“barby-chunky_png”、“png”和“RubyInline”吗?
    • 如果我在 config/environment.rb 中包含 barby gems,我会得到 config/environment.rb:8:in &lt;top (required)&gt;': undefined local variable or method config' for main:Object (NameError)
    • 我给出的与 rails 2.3.8 相关的链接如果您使用的是 rails 3+,那么您需要根据该链接进行更改。 house9.blogspot.in/2011/10/generating-barcodes-with-ruby-and-rails.html 最后使用img标签就可以显示条码了。
    【解决方案2】:
    File.open('code128b.png', 'w'){|f|
      f.write barcode.to_png(:height => 20, :margin => 5)
    }
    

    这是在您的根应用路径中创建文件“code128b.png”,并 &lt;%= image_tag("code128b.png") %&gt; 从 assets/public 调用图像

    为什么您不将条形码上传到 cloudinary 并将其作为 url 保存到您的数据库中 :)

    【讨论】:

      猜你喜欢
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多