Brian, unfortunately these settings have any effect on string to float conversion performed by the validators.

Take a look at these methods from Rails 3 beta 4:

     def parse_raw_value_as_a_number(raw_value)
        case raw_value
        when /\A0[xX]/
          nil
        else
          begin
            Kernel.Float(raw_value)
          rescue ArgumentError, TypeError
            nil
          end
        end
      end

      def parse_raw_value_as_an_integer(raw_value)
        raw_value.to_i if raw_value.to_s =~ /\A[+-]?\d+\Z/
      end

The locale support you are talking about is only related to number helpers like those you have mentioned...

I'm talking about extending this notion of locale support for numbers.

Rodrigo.

Em 25-06-2010 11:10, Brian Lopez escreveu:
Hi Rodrigo,
I think the proper way to do this is to override those formats in your translation yaml files (config/locales). For reference of what the keys are take a look at http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L7-9 You'll notice that those I18n keys are used in the number helpers like in `number_with_delimiter` here: http://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/number_helper.rb#L209

You'll have to create a file like `config/locales/pt-BR.yml` and at the very least add those number I18n keys for separator and delimiter.

-Brian

On Jun 25, 2010, at 6:31 AM, Rodrigo Rosenfeld Rosas wrote:

What is the suggested path for dealing with number formats in Rails?

Even if we set locale to pt-BR, for instance, if the user inputs a number like '1.000,00' or '1000,00' in a form input, numerical validation will yield an 'invalid_number' error, even though this is a valid format in Brazil.

I could monkey patch overriding parse_raw_value_as_a_number to replace '.' with '' and ',' with '.' in ActiveModel::Validations::NumericalityValidator but that wouldn't solve the problem because the application is internationalized. So, even if I monkey patch this method, I would have to take into consideration the current user locale before parsing the number...

Are there any plans for supporting this on Rails 3?

Rodrigo.

--
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