Using barcode-generator's 'barcode' method in the model


I am using matisimitsu’s barcode-generator for barcodes in PDFs with
Prawn and Prawnto.

I want to use the barcode method in a model where i generate the PDF
as a mail attachment, so that I can do this

def with_attachment(pdfFile, customer)
subject “Voucher”
from “[email protected]

part :content_type => "text/html",
  :body => render_message("with_attachment", :customer =>


attachment :content_disposition => "attachment",
    :body => pdfFile,
    :content_type => "application/pdf",
    :filename => 'voucher.pdf'



Where generate_pdf_voucher is a method in the Customer model and
renders a PDF Document.

But right now, im getting the following error

NoMethodError: undefined method `barcode’ for #Customer:0x23fcf94

How can I get around this problem? barcode_generator extends
ActionView to add the barcode method.

For now, I’ve copied the code into the Customer model and required the
imagemagick_wrapper in the model to get this to work. It works fine
but is there no cleaner way?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs