Skip to content
Tags

,

adding column of class BigDecimal

May 5, 2011

I recently tried adding a price column using the following line of code

    add_column :variants, :sale_price, :decimal, :default => 0.0

I was expecting it to add a BigDecimal field, but it ended up adding a Fixnum field.

So I had to use this line of code

    add_column :variants, :sale_price, :decimal, :precision => 8, :scale => 2, :default => 0.0

That adds 8 digits before the decimal point and 2 digits after.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: