jeudi 17 mars 2016

Cannot get exact value on parameter

I have sample parameter below:

Parameters: {
          "utf8"=>"✓",
          "authenticity_token"=>"xxxxxxxxxx",
          "post" => {
              "product_attributes" => {
                  "name"=>"Ruby",
                  "product_dtls_attributes" => {
                      "0"=>{"price"=>"12,333.00"},
                      "1"=>{"price"=>"111,111.00"}
                  },
              },
          "content"=>"Some contents here."
        }

Now, the scenario is, I cannot get the price exact value in model.

Instead of:

  1. price = 12,333.00
  2. price = 111,111.00

I get:

  1. price = 12.00
  2. price = 11.00

And now here is what I did in my code:

before_validation(on: :create) do
  puts "price = #{self.price}" # I also tried self.price.to_s, but didn't work.
end

Note:

column price is float

The question is, how can I get the exact value of params price. Thanks!

Aucun commentaire:

Enregistrer un commentaire