Hi i have create a PDF conversion in my rails application using Prawn and it working fine.
Now i am sending that PDf in an email attachment. Now problem is that i can send PDF attachment if i do not use any helper method, but when i use my format_currency method in PDf file it gives error on instance_eval method. here is my code sample:
format currency code:
module ApplicationHelper
def format_currency(amt)
unit = 'INR'
country = current_company.country
if !country.blank? && !country.currency_unicode.blank?
unit = country.currency_unicode.to_s
elsif !country.blank?
unit = country.currency_code.to_s
end
number_to_currency(amt, :unit => unit+" ", :precision=> 2)
end
end
My controller code :
pdf.instance_eval do
@company = current_company
@invoice = invoice
@invoice_line_items = invoice_line_items
@receipt_vouchers = receipt_vouchers
eval(template) #this evaluates the template with your variables
end
the error message i got :
undefined method `format_currency' for #<Prawn::Document:0x7f89601c2b68>
with this code i can send attachment successfuly if i don’t use helper method but i need to use that method.
I have fixed this issue in a different manner, i have created a new currency_code method in my company model and called that in my format_currency helper method and it is working for me fine:
Here is what i have done :
and used it in my format_currency helper :
and in my controller i have added a variable for currency and used it in my pdf file: