How to populate a sql db with t.decimal precision and scale via rails c -
t.decimal "eur", precision: 8, scale: 2
this row in database table (name wallet). how can populate data in rails console?
i have tried
wallet.eur=10
ok 1 easy , doesnt work.
wallet.eur=bigdecimal.new('154.00')
1 throws => #<bigdecimal:56cadb8,'0.154e3',9(18)>
cant save , stay @ 0.0.
any idea or suggestion?
use built-in rails facilities, check numberhelper documentation examples.
use code add migration:
add_column :items, :price, :decimal, :precision => 8, :scale => 2
and use method:
number_to_currency(price, :unit => "€")
if you've got nomethoderror add line:
include actionview::helpers::numberhelper
Comments
Post a Comment