Hola a todos, espero se encuentren muy bien.
Estoy trabajando en un Rails app que genera tarjetas kanban para la compania donde trabajo, de igual manera debe generar archivos .jpg que contienen los codigos de barras utilizando un gem llamado Image Magick y otro llamado Barby.
Tengo un problema con mi metodo actual, le agregue un ciclo para insertar los registros en base a un contador, pero obtengo un ciclo infinito.
Anexo el codigo, alguna idea cual es el best practice para insertar registros de esta manera?
De antemano muchas gracias, saludos a todos.
Jaime.
#require 'rubygems'
require 'barby'
require 'barby/barcode/code_39'
require 'barby/outputter/rmagick_outputter'
#Extension to include barcode data below the image
module Barby
class CustomRmagickOutputter < RmagickOutputter
register :to_image_with_data
def to_image_with_data
#Make canvas bigger
canvas = Magick::ImageList.new
canvas.new_image(full_width , full_height + 10)
canvas << to_image
canvas = canvas.flatten_images
#Make the text
text = Magick::Draw.new
text.font_family = 'helvetica'
text.pointsize = 14
text.gravity = Magick::SouthGravity
text.annotate(canvas , 0,0,0,0, barcode.data)
canvas
end
end
end
class CardController < ApplicationController
def new
@card = Card.new
end
def create
@card = Card.create(params[:card])
finish = @card.finish
@card.start = 2
until @card.start > finish
@card.start += 1
@card = Card.create(params[:card])
file_name = @card.barcode
barcode = Barby::Code39.new(file_name)
barcode.to_image_with_data.write("app/assets/barcodes/#{file_name}.png")
end
if @card.save
redirect_to(:action => 'lookup')
else
render('new')
end
end
def lookup
@cards = Card.all
end
def print
@card = Card.find(params[:id])
end
def edit
@card = Card.find(params[:id])
end
def update
@card = Card.find(params[:id])
if @card.update_attributes(params[:card])
redirect_to(:action => 'lookup')
else
render('edit')
end
end
def delete
@card = Card.find(params[:id])
end
def destroy
Card.find(params[:id]).destroy
redirect_to(:action => 'lookup')
end
end