Lut
Lut

Reputation: 1533

Barcode not showing on rails [Barby Gem]

Gems used

Ruby '1.9.3'

Rails '3.2.11'

Bbarby', '~> 0.5.1'

Chunky_png', '~> 1.3.0'

Application Helper

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'

Controller

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)
}

View

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

The pages renders but not the barcode:

enter image description here

Upvotes: 1

Views: 2086

Answers (2)

tardjo
tardjo

Reputation: 1654

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

this is create file "code128b.png" in your root app path, and <%= image_tag("code128b.png") %> call image from assets / public

why you not upload your barcode into cloudinary and save it as url into your db :)

Upvotes: 0

VDN
VDN

Reputation: 516

Please find the link for detailed bar code implementation :

http://blog.andolasoft.com/2012/11/how-to-generate-barcode-using-barby-gem-in-rails-2-3-8.html

Upvotes: 1

Related Questions