Rails number_field alternative for decimal values

前端 未结 2 1217
时光取名叫无心
时光取名叫无心 2020-12-07 21:34

I\'m trying to accept a decimal value (USD, so 12.24 would be an example) with the number_field method.

<%= f.number_fiel
2条回答
  •  情深已故
    2020-12-07 22:25

    For price fields you can use this:

    f.number_field :price, value: @item.price ? '%.2f' % @item.price : nil, min: 0, step: 0.01
    

    It works fine even if you allow blank values.

提交回复
热议问题