Open aribeiro opened 11 years ago
Hi,
I'm using has_barcode here, and I'd like to define the barcode type based on the type the user defined in a form. it is possible to give me an example, I'm trying something like this:
class MyModel < ActiveRecord::Base include HasBarcode BARCODE_SYMBOLOGY = { :CODE25 => Barby::Code25, :CODE25INTERLEAVED => Barby::Code25Interleaved, :CODE25IATA => Barby::Code25IATA, :CODE39 => Barby::Code39, :CODE93 => Barby::Code93, :CODE128 => Barby::Code128, :GS1138 => Barby::GS1128, :EAN13 => Barby::EAN13, :BOOKLAND => Barby::Bookland, :UPCA => Barby::EAN13, :EAN8 => Barby::EAN8, :UPCEAN => Barby::UPCSupplemental } has_barcode :barcode, :outputter => :png, :type => Proc.new {|p| BARCODE_SYMBOLOGY[p.barcode_symbology.to_sym] rescue Barby::Code39 }, :value => Proc.new { |p| p.barcode_string } ...
I'm getting the error: NoMethodError: undefined method `new' for #Proc:0x007f81dd93f8f8
So the user will save the barcode_string and the barcode_symbology like CODE39, and it should generate the barcode based in this two fields.
Thanks
I think you want to use
proc {|p| BARCODE_SYMBOLOGY[p.barcode_symbology.to_sym] rescue Barby::Code39 }
Hi,
I'm using has_barcode here, and I'd like to define the barcode type based on the type the user defined in a form. it is possible to give me an example, I'm trying something like this:
I'm getting the error: NoMethodError: undefined method `new' for #Proc:0x007f81dd93f8f8
So the user will save the barcode_string and the barcode_symbology like CODE39, and it should generate the barcode based in this two fields.
Thanks