I have a problem to generate barcodes in production environment

118 views
Skip to first unread message

Leonel Cutipa

unread,
Jan 18, 2016, 3:09:25 PM1/18/16
to Barby
Hello,

I'm new using Barby Gem and generating barcodes. I'm working in Rails 4 and Postgresql.

The Barby gem work fine in DEVELOPMENT ENVIRONMENT, I created and printed a lot of barcodes without problems to read using a handheld scanner and cellphone's apps.

I have a problem: In PRODUCTION ENVIRONMENT the Barby Gem not work fine. I generate barcodes in a png files and I printed. When using a handheld scanner or cellphone's apps to read printed out barcodes back into the computer the numbers of the barcodes are wrong.

For example: I created the barcode 744, but when scanned barcode always show the number 653. 

All barcodes created and printed in production environment always are same, with the number 653.

This is the code

Controller:

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

def show
   respond_with(@extintor)
   @extintors = Extintor.where(pro_estado: 0)
   @producto = Producto.all
   @clientes = Cliente.all
   barcode_value = sprintf('%012d', @extintor.ext_codigo)
   barcode = Barby::Code128.new(barcode_value)
   @blob = Barby::PngOutputter.new(barcode).to_png #Raw PNG data
   files_path = "app/assets/images/ext_barcode.png"
   File.open(files_path, 'wb') { |f| f.write @blob }
end

View:

<div id="myPrintCode">
   <center>
      <font face="Arial" size="0.5">
      <%= @extintor.producto.pro_sigla %>
      </font>
      <br>
      <%= image_tag("ext_barcode.png", size: "208x50") %>
      <br>
      <font face="Arial">
      <%= sprintf('%012d', @extintor.id) %>
      </font>
   </center>
</div>


I hope to help me. 
Thanks in advance.

Tore Darell

unread,
Jan 20, 2016, 5:43:01 PM1/20/16
to ruby-...@googlegroups.com
This is likely a problem with Rails caching or the fact that you're
using the same filename all the time. You should probably not be
writing to the file system, but render the data directly from a
controller.
> --
> You received this message because you are subscribed to the Google Groups
> "Barby" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ruby-barby+...@googlegroups.com.
> To post to this group, send email to ruby-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/ruby-barby.
> For more options, visit https://groups.google.com/d/optout.

Gunnar Wolf

unread,
Jan 20, 2016, 5:54:07 PM1/20/16
to ruby-...@googlegroups.com

Besides what Tore pointed out, using a static filename from within a Web app opens a can of worms security-wise, particularly a race condition. What happens when two users request the barcode at roughly the same time? They are served the same content! Surely not what you want.

Braian Dickson

unread,
Feb 11, 2016, 3:31:24 PM2/11/16
to Barby
Hola, Leonel. Te molesto con unas preguntas. Necesito implementar un generador de codigos de barra para la app. Me gustaria saber si tuviste que crear un modelo para los codigos generados y si tuviste que hacer algun tipo de relacion entre estos. No se como haras para imprimirlos, yo pensaba Poner un boton en la tabla de productos y que este mismo abra una ventana de impresion en el navegador y ahi realizar tantas copias como se requieran.
Otra cosa que me gustaria preguntarte es si agregas mas contenido ademas del codigo de barra, como nombre del producto o algun otro tipo de informacion a los codigos.

Un saludo y suerte con tu problema!
Reply all
Reply to author
Forward
0 new messages