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

**URL:** <https://www.ruby-forum.com/t/using-barcode-generators-barcode-method-in-the-model/175462>\
**Category:** Rails\
**Created:** [September 14, 2009, 10:22am UTC](https://www.ruby-forum.com/t/using-barcode-generators-barcode-method-in-the-model/175462 "2009-09-14T10:22:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [September 14, 2009, 10:22am UTC](https://www.ruby-forum.com/t/using-barcode-generators-barcode-method-in-the-model/175462/1 "2009-09-14T10:22:48Z")

</div>

Hi,

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](http://github.com/matsimitsu/barcode-generator/tree/master).

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 customer.email  
from “[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)”

```
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.

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [September 14, 2009, 10:46am UTC](https://www.ruby-forum.com/t/using-barcode-generators-barcode-method-in-the-model/175462/2 "2009-09-14T10:46:14Z")

</div>

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?
