-2

在正常形式中,我使用了这个:

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

这会在适当的位置添加逗号。如果我必须将此分隔符用于 best_in_place gem 怎么办:

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

如何在我的编辑页面中为金额字段添加逗号?有人可以帮助我吗?

4

2 回答 2

1

您需要在模型的 get_invoice_amount_with_precision 方法中使用 number_with_precision。为了使其可访问,您需要在模型中包含 ActionView::Helpers::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
于 2012-08-13T12:27:27.807 回答
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
于 2012-10-05T00:02:32.500 回答