2013-04-03 14 views
0

我正在使用Prawn PDF處理PDF發票。我正在嘗試使用number_to_currency,同時通過unit在蝦PDF中添加貨幣單位? (語法錯誤)

def line_item_rows 
[["Description", "Qty", "Unit Price", "Price GBP"]] + 
@invoice.line_items.map do |item| 
    [item.name, item.quantity, price(item.unit_price), price(item.full_price)] 
end 
end 

@view.number_to_currency(num, :unit => "£") 

一個錯誤上述結果:

syntax error, unexpected $end, expecting ')' 
@view.number_to_currency(num, :unit => "£") 
              ^): 

如果我使用HTML值,而不是簡單地輸出原始的HTML:

@view.number_to_currency(num, :unit => "£") 
Total £2,266.00 

是否有添加的一種特殊的方式£使用Prawn PDF時?上述嘗試在使用html/erb時正常工作,但在使用Prawn PDF時不能正常工作。

回答

2

紅寶石可能不處理你的源文件爲UTF-8:

# encoding: US-ASCII <-- it's defaulting to this 
puts "£" 

所以當它編譯:

$ ruby foo.rb 
foo.rb:2: invalid multibyte char (US-ASCII) 
foo.rb:2: invalid multibyte char (US-ASCII) 
foo.rb:2: syntax error, unexpected $end, expecting ')' 
puts("£") 
     ^

在你的文件的頂部添加了編碼提示:

# encoding: utf-8 
puts("£") 

它應該運行:

$ ruby foo.rb 
£ 
+0

那就修好了,謝謝! – dannymcc 2013-04-03 23:46:29