相关疑难解决方法(0)

带小数精度的Formtastic数字字段?

当然我错过了一些非常明显的东西......我有一个十进制精度为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
Run Code Online (Sandbox Code Playgroud)

视图

%td= bought.input :sales_price, input_html: { class: 'span2'}, label: false
Run Code Online (Sandbox Code Playgroud)

注意到下面的回答,其他人在以后发现这个问题可能并不清楚:

%td= bought.input :sales_price, input_html: { class: 'span2', value: number_with_precision(bought.object.sales_price, precision: 2)}, label: false
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails formtastic

5
推荐指数
1
解决办法
2166
查看次数

标签 统计

formtastic ×1

ruby-on-rails ×1