# Specifying a decimal field precision/scale with scaffold requires 2 steps?

**URL:** <https://www.ruby-forum.com/t/specifying-a-decimal-field-precision-scale-with-scaffold-requires-2-steps/186298>\
**Category:** Rails\
**Created:** [April 4, 2010, 1:03am UTC](https://www.ruby-forum.com/t/specifying-a-decimal-field-precision-scale-with-scaffold-requires-2-steps/186298 "2010-04-04T01:03:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2010, 1:03am UTC](https://www.ruby-forum.com/t/specifying-a-decimal-field-precision-scale-with-scaffold-requires-2-steps/186298/1 "2010-04-04T01:03:11Z")

</div>

Hi,

It appears to me that the command:  
ruby script/generate scaffold whatever money\_field:decimal(10,2)  
will not generate a valid migration.

Therefore it appears to me only two ways to achieve the desired result  
is:

1.1 Omit the the precision/scale on the scaffold command  
1.2 Edit the migration file by following the “do |t| … end” with  
the command:

change\_column :whatever :money\_field, :amount, :decimal,  
:precision  
=\> 10, :scale =\> 2  
I think this approach worked for me

2.1 Omit the money\_field in it’s entirety  
2.2 Create a second migration file an add the command:

add\_column :whatever :money\_field, :amount, :decimal, :precision  
=\> 10, :scale =\> 2  
I’m guessing this will work as well

BTW, I’m running Rails 2.3.5, Ruby 1.8.6, WinXP-Pro/SP3, Firefox  
3.6.2, Firebug 1.5.3,  
MySQL 5.0.37-community-nt, Mongrel, Apache HTTP Server 2.2.15

What do you think?

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2010, 1:35am UTC](https://www.ruby-forum.com/t/specifying-a-decimal-field-precision-scale-with-scaffold-requires-2-steps/186298/2 "2010-04-04T01:35:27Z")

</div>

On Sat, Apr 3, 2010 at 4:02 PM, RichardOnRails \<  
removed\_email\_address@domain.invalid\> wrote:

> Hi,
> 
> It appears to me that the command:  
> ruby script/generate scaffold whatever money\_field:decimal(10,2)  
> will not generate a valid migration.

Yes, the syntax is invalid and the correct syntax should be:

ruby script/generate scaffold whatever money\_field:decimal

Next, you’ll simply have to edit the migration file to add the scale  
option.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2010, 3:14am UTC](https://www.ruby-forum.com/t/specifying-a-decimal-field-precision-scale-with-scaffold-requires-2-steps/186298/3 "2010-04-04T03:14:58Z")

</div>

Thanks, Conrad.

I thought since we’re on Rails 2 there’d be a better way. But I guess  
that scaffold is going to be deprecated soon, so core members don’t  
want to do any more work on it. Too bad, because it’s a way neat to  
get a concept-demo fast and amaze prospective clients.

Best wishes,  
Richard
