dpickett / has_barcode

Nice class method wrapper for barby
MIT License
52 stars 18 forks source link

ActionView::Template::Error (data is not valid (extended=false)): on user.barcode_data.html_safe #5

Open mclark4386 opened 12 years ago

mclark4386 commented 12 years ago

user modal has: has_barcode :barcode, :outputter => :svg, :type => :code_39, :value => Proc.new { |c| c.tehID }

def tehID self.nid end

(tried :svg and :png[with chunky_png installed] both give same error) And in the view I have: <%= current_user.barcode_data.html_safe %>

and when I try to load the page I get the following error: Completed 500 Internal Server Error in 4ms

ActionView::Template::Error (data is not valid (extended=false)): 6:

7:
8: <%= current_user.barcode_data.html_safe %> 9:
10:
11: <% else %> app/views/users/show.html.erb:8:in `_app_views_users_show_html_erb___1179557980136249438_70109681266960'

Any help would be very much appreciated!

cestrada commented 9 years ago

Error is caused by special characters like "_".

awinabi commented 8 years ago

For code 39 style barcodes only 43 characters are defined. Passing anything other than these 43 characters to be barcodified will result in this error.

This is because has_barcode internally uses the barby gem and referring to the source for code_39, the error is triggered from line 97 https://github.com/toretore/barby/blob/master/lib/barby/barcode/code_39.rb#97 , which happens when the valid? function returns false.

As you can see for a non-extended encoding, the characters passed should be part of ENCODINGS https://github.com/toretore/barby/blob/master/lib/barby/barcode/code_39.rb#L12-L35 .

So passing lower case characters will throw an error as well.