【发布时间】:2012-01-13 21:56:20
【问题描述】:
我肯定遗漏了一些非常明显的东西...我有一个精度为 2 的小数字段,但 Formtastic 只显示一个小数点,除非实际值有 2 个位置。我错过了什么?
型号:
create_table "items", :force => true do |t|
t.string "item_number"
t.integer "buyer_id"
t.integer "seller_id"
t.string "description"
t.decimal "sales_price", :precision => 10, :scale => 2, :default => 0.0
t.datetime "created_at"
t.datetime "updated_at"
end
查看
%td= bought.input :sales_price, input_html: { class: 'span2'}, label: false
注意下面的答案,其他人以后可能不清楚:
%td= bought.input :sales_price, input_html: { class: 'span2', value: number_with_precision(bought.object.sales_price, precision: 2)}, label: false
【问题讨论】: