@Brian and Matt:

I think you misunderstand what I was trying to say. I'm not an i18n
newcomer and I should know most of the i18n stuff in NumberHelper
since it was written by me! ;-)

What I was trying to say is that Rails i18n handles the number output
but not the input: A user from a country where the comma is used as
the decimal separator wants to say the product's price is 19,95 (not
19.95) and therefore use this in a text field (and also see it in this
format again when they come back to edit it). What I sure can do is
something like the following:

  # in the model
  def price=(price)
    price = price.gsub(/[^0-9#{I18n.t(:'number.format.separator')}]/,
'').gsub(I18n.t(:'number.format.separator'), '.') if price.is_a?
(String)
    write_attribute(:price, price)
  end

  # in the view
  <%= f.text_field :price, :value => number_to_currency
(@product.price, :unit => '') %>

This is in fact pretty much what I do in my delocalize plugin that I
linked above. However, it's definitely not a nice thing to do if you
have an application that relies heavily on number input. And this is
what my post was about.

@Colin:

Your concern seems valid at first but it probably isn't. The change
I'd propose relies on database column types, so if price is a numeric
column it can't ever take a literal string (or, rather, it
automatically converts it to a number - so @product.price = '19,95'
would become 19.0 and @product.price = 'a string' would become 0.0).

Or am I misunderstanding the point you're trying to make?

In any case: Thanks for the feedback so far - it helped me see that I
needed to present my ideas more clearly.

- Clemens
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to