@cart_total = @line_items.select{|x| x.product.present? }.collect{ |x| (x.product.price*x.quantity) }.inject(:+) || 0
final_amount = @cart_total
params[:order].merge!(:final_amount => final_amount)
return render :text => "#{params[:order][:final_amount]} => #{params[:order]}"
38.0 => {"shipping_id"=>"1", "ship_day"=>"任意日期", "ship_special"=>"", "ship_time2"=>"任意时间段", "part_pay"=>"4", "payment"=>"wxpay", "memo"=>"", "is_tax"=>"false", "tax_company"=>"", "ship_zip"=>"", "ship_tel"=>"", "ip"=>"127.0.0.1", "member_id"=>4451, "supplier_id"=>1, "status"=>"active", "final_amount"=>#}
也就是说,params[:order][:final_amount] = 38.0
, 而params[:order]
中的最后一项值为::final_amount => #
但若是把final_amount = @cart_total
改为final_amount = @cart_total.to_i
, 那么一切都正常,params[:order]
中的最后一项值为::final_amount => 38.0
另外,@cart_amount.kind_of(Integer)
的结果是 true.
请问为什么会出现这种情况?@cart_total
的值为什么需要 to_i 后才能在params[:order]
中正常显示?为什么params[:order][final_amount]
就可以直接显示?