I'm facing a problem with Rails application to store decimals in my mysql database. I have a form with two fields: "amount" and "currency". When I enter a decimal value in the "amount" field (for example 1,22) Rails just stores the 1 in the database.
My log file looks like this:
Started POST "/cashamounts" for 127.0.0.1 at 2012-02-04 13:23:54 +0100
Processing by CashamountsController#create as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"QpWGfEtDR1tc7wTFmZZst9gYjKAyXtRypilsxDE9Tzs=", "cashamount"=>{"currency_id"=>"eur", "amount"=>"1,22"}, "commit"=>"Create Cashamount"}
[1m[36mCurrency Load (2.8ms)[0m [1mSELECT `currencies`.* FROM `currencies` ORDER BY name[0m
[1m[35m (0.2ms)[0m BEGIN
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO `cashamounts` (`amount`, `created_at`, `currency_id`, `updated_at`) VALUES (1, '2012-02-04 12:23:54', 'eur', '2012-02-04 12:23:54')[0m
[1m[35m (0.6ms)[0m COMMIT
Redirected to http://localhost:3000/cashamounts/8
Completed 302 Found in 94ms
So the amount is stored in the params correctly, but is not inserted correctly into the database. I checked my db/schema.rb file. The line for the column "amount" is:
t.decimal "amount", :precision => 10, :scale => 2
Where else can I look to find the problem?
PS. I started off with using the money gem, but that showed the same problem: all digits after the "," are not stored.
1.22?currencies.* FROMcurrenciesORDER BY name [1m[36m (0.2ms)[0m [1mBEGIN[0m [1m[35mSQL (0.5ms)[0m INSERT INTOcashamounts(amount,created_at,currency_id,updated_at) VALUES (1, '2012-02-04 13:05:27', '', '2012-02-04 13:05:27')