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


I am using matisimitsu's barcode-generator for barcodes in PDFs with Prawn and Prawnto. GitHub - matsimitsu/barcode-generator: Rails plugin to generate/display barcode in your views.

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"     recipients     from "<>"

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

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

Mailer.deliver_with_attachment(customer.generate_pdf_voucher, customer)

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?