Ruby on rails 发送、接收并神秘更改的强参数(Ruby和jQuery)

Ruby on rails 发送、接收并神秘更改的强参数(Ruby和jQuery),ruby-on-rails,Ruby On Rails,我不知道为什么会发生这种情况,但在重新加载页面后,这种情况会持续发生。我在我的params中发送credit\u amount,控制器获取它们,但在更新找到的记录时,它以某种方式恢复为0。这很奇怪 以下是服务器日志的内容: Processing by CustomersController#update as JSON Parameters: {"id"=>"89", "credit_amount"=>"$75.01"} Shop Load (0.2ms) SELECT "sho

我不知道为什么会发生这种情况,但在重新加载页面后,这种情况会持续发生。我在我的
params
中发送
credit\u amount
,控制器获取它们,但在更新找到的记录时,它以某种方式恢复为0。这很奇怪

以下是服务器日志的内容:

Processing by CustomersController#update as JSON
Parameters: {"id"=>"89", "credit_amount"=>"$75.01"}
Shop Load (0.2ms)  SELECT  "shops".* FROM "shops" WHERE "shops"."id" = ? LIMIT 1  [["id", 1]]
Customer Load (0.1ms)  SELECT  "customers".* FROM "customers" WHERE "customers"."id" = ? LIMIT 1  [["id", 89]]
(0.1ms)  begin transaction
Customer Exists (0.2ms)  SELECT  1 AS one FROM "customers" WHERE 
("customers"."fresh_customer_id" = '6474232467' AND "customers"."id" != 89) 
LIMIT 1
这是有趣的部分,在此之前,
credit\u金额为75.01美元,现在低于0.0美元:

SQL (0.2ms)  UPDATE "customers" SET "credit_amount" = ?, "updated_at" = ? 
WHERE "customers"."id" = ?  [["credit_amount", 0.0], 
["updated_at", "2017-04-25 22:25:57.428297"], ["id", 89]]
这是接收和处理数据的Ruby控制器:

def update
  @customer = Customer.find(customer_params)
  update_amount = params["credit_amount"].to_f
  @customer.update(credit_amount: update_amount)
  render json: {id: customer_params, credit_amount: update_amount}
end

在调用
至\u f
之前,从金额中删除
$
。类似这样的事情可能会有所帮助:

update_amount = params["credit_amount"].tr("$", "").to_f

可能是您正在使用一个字符串,而db需要一个数字?鹰眼Gerry!非常感谢,事情就是这样。我只是觉得我快疯了。