I have a price field in my db, :decimal, :null => false, :default =>
0
When I open a new form field to create a new record, this value is
displayed as "0.0". This is not so pretty for a field in which a
price like "123.45" is expected. Ideally I would like to have the
field blank (I'll validate for numeric at submit time). I'm aware of
the format_as_currency helper, but I am not sure how/if I would use it
in a form context.
Bonus question: I am currently validating acceptable characters in a
javascript onkeyup event (get rid of anything not a digit, decimal or
comma). Is there anything that comes for free that I have missed, or
a good plugin out there to help with what I would think is a fairly
common use case?
Thanks. Yes, your solution will fix the display, but...
The migration defines both the type of the object within the Rails
context, but also the actual database field definition, right? If I
want to have very basic data integrity, using not null, defaults (not
to mention explicit foreign key constraints) is a "best practice"
which I am pretty sure is still in force in the Rails world.
Any other ideas on how I can change the display of my data without
changing the migration and database column definitions?