使用十进制字段在rails中提交表单

时间:2016-12-29 21:49:49

标签: ruby-on-rails ruby ruby-on-rails-4

我在存储具有十进制特征的字段时遇到问题,当字段包含一个常规整数时,它会完美地存储,但是当我输入一个像88.88这样的数字时,params将其作为nil,或者有时作为8888没有该点。< / p>

# error
NoMethodError in Admin::ProductsController#update
undefined method `*' for nil:NilClass


# schema.rb
  create_table "products", force: :cascade do |t|
    t.decimal  "public_price",  precision: 8, scale: 2
  end


# Parameters:

{"utf8"=>"✓",
 "_method"=>"patch",
 "authenticity_token"=>"YiAjcS2nT466GHO96QF05yyK+kcHTjPznbB4Rm4JvdHj3kdcEoYAp3wlVDmyx1PoOfDfR5/C47b1fw57BCJb+w==",
 "product"=>{"product_type"=>"product", "model"=>"E3RRss","brand"=>"MMM", "unity"=>"kg", "cost"=>"", "public_price"=>"", "desc"=>""},
"commit"=>"save",
"id"=>"7"}

# _form.html.erb

<%= simple_form_for(product, url: url) do |f| %>
  <%= f.error_notification %>
    ....
    <%= f.input :public_price, label: "Price", required: true %>
    ....
<% end %>

0 个答案:

没有答案