2012-08-13 66 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