Decimal fields generated in Rails 2.3.5 act like strings, sort of

Hi All,

I just created a new CRUD “expense” (using Rails 2.3.5 scaffold) which
included “amount:decimal”. When I:

  1. populated the amount field of a new expense with 5 characters:
    12.50 and
  2. saved the new record

I got a display of the new record that showed Amount to be merely
“12”.

I clicked Update and put my cursor over the data field for Amount and
got a tool-tip display of 12.50.

On the other hand, Date seems to be handled fine IMHO, both on input
and display.

Is the problem that MySQL 2.0.37 doesn’t really implement “decimal”
and so I should switch to float and then do my own formatting for a
text field?

Thanks in Advance,
Richard

RichardOnRails wrote:

I just created a new CRUD “expense” (using Rails 2.3.5 scaffold) which
included “amount:decimal”. When I:

  1. populated the amount field of a new expense with 5 characters:
    12.50 and
  2. saved the new record

I got a display of the new record that showed Amount to be merely
“12”.

I clicked Update and put my cursor over the data field for Amount and
got a tool-tip display of 12.50.

On the other hand, Date seems to be handled fine IMHO, both on input
and display.

Is the problem that MySQL 2.0.37 doesn’t really implement “decimal”
and so I should switch to float and then do my own formatting for a
text field?

MySQL 2.0.37? Wow! I’m shocked that’s even useable with Rails, or
anything else modern.

That being said I assume you added the :precision and :scale for the
field to your migration? If so then yes, you might have issues with that
old of a version of MySQL.

Hi Robert,

Thanks for your help. I mistakenly reported MySQL’s version as
2.0.37. It’s actually 5.0.37. But that’s a little behind the times,
so I upgraded to 5.1.44 which seems to work fine in general.

But I ran into a snag getting my RoR working with 5.1.44. I think the
problem is I only dumped/imported the development database.

I’d like to find a good way to be able to switch back and forth
between MySQL versions on a WinXP/SP3 platform. I’m going to post a
second question on this if Google doesn’t turn up any thing good for
me.

Best wishes,
Richard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs