0

Im using Ruby 2.4.1 with rails 5.0.2

Here is my code:

total_price = 600.0
o = client.bills.new(client_id: client, total_price: total_price.to_f)
#<Bill id: nil, client_id: 21, created_at: nil, updated_at: nil, total_price: 0.6e3, bill_id: nil, discount_price: nil>
o.save

it will save as 0.00 instead of 600.0 or 0.6e3 in my PostgreSQL. Oh, im using Numeric(8,2) as its datatypes which is decimal, :precision => 8, :scale => 2

My migration:

add_column :bills, :total_price, :decimal, :precision => 8, :scale => 2

Any clues?

8
  • total_price: 0.6e3 is not zero. Commented Apr 7, 2017 at 5:25
  • yes true.. but when is save, it save as 0.00 Commented Apr 7, 2017 at 5:26
  • 1
    could you please add your migration and schema/structure file? Commented Apr 7, 2017 at 5:34
  • 1
    show me the output of o.update_column(total_price: 123.45). If that works it means you have some validation or something else preventing the correct number to be saved Commented Apr 7, 2017 at 5:48
  • @AndreyDeineko it return 0.12345e3 but still save it as 0.00 Commented Apr 7, 2017 at 6:18

1 Answer 1

1

I think you have some validation/callback preventing the correct value to be written to database. Double check validations/callbacks in Bill model.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right.. i forgot that i have callback after_create.. thanks for your hint!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.