2012-08-13 78 views
-2

在正常的形式添加分隔符我已經使用這個:爲best_in_place寶石

<td> 
    <%= number_with_precision(approved_invoice.invoice_amount, 
     :precision =>2, 
     :delimiter => ",") 
    %> 
</td> 

這在適當的地方加上逗號。如果我要使用這個分隔符best_in_place寶石:

<td class="tax-particulars-align"> 
    <%= best_in_place @invoice, :invoice_amount, 
     :display_as => :get_invoice_amount_with_precision, 
     :type => :input 
    %> 
</td> 

我可如何向量場逗號在我的編輯頁面?有人可以幫助我嗎?

+0

誰能給我什麼建議嗎? – 2012-08-13 12:27:02

回答

1

您需要在模型的get_invoice_amount_with_precision方法中使用number_with_precision。爲了使這種訪問,您將需要包括::的ActionView ::助手在NumberHelper模型:

class MyModel < ActiveRecord::Base 
    include ActionView::Helpers::NumberHelper 

    def get_invoice_amount_with_precision 
    number_with_precision(invoice_amount, :precision => 2, :delimiter => ',') 
    end 
end 
+0

感謝您的建議,我會嘗試。 – 2012-08-13 12:42:54

+0

謝謝,我試過了,它的工作正常。 – 2012-08-14 04:38:14

0

,作爲最佳替代1.0.3您可以以決定使用自定義的方法,模型如何顯示某個字段。你可以寫這樣的事情(在視圖中):

best_in_place @user, :description, :type => :textarea, :display_as => :my_formatting 

和模型:

class MyModel < ActiveRecord::Base 

    include ActionView::Helpers::NumberHelper 

    def my_formatting 
    number_with_precision(description, :precision => 0, :delimiter => " ") 
    end 
end