This project is archived and is in readonly mode.
number_to_currency fails with "NoMethodError: undefined method `>=' for nil:NilClass"
-
Carlos Antonio da Silva
- Tag changed from rails 3.0.0.beta3 to rails 3.0.0.beta3, action_view, number_helper
Just tested here following the same steps, using both Ruby 1.8.7-p249 and 1.9.2-head with Rails 3.0.0.beta3 in a fresh app, nothing wrong.
ruby-1.8.7-p249 > foo.number_to_currency(101.00) => "$101.00" -
Santiago Pastorino
- Tag changed from rails 3.0.0.beta3, action_view, number_helper to rails 3.0.0.beta3, action_view, bugmash, number_helper
-
Santiago Pastorino
Fabian, can you try it using the latest Rails version from git?.
Thanks -
Enrico Bianco
not reproducible in the latest master:
ruby-1.8.7-p249 > foo.number_to_currency(101.00) => "$101.00" ruby-1.9.1-p378 > foo.number_to_currency(101.00) => "$101.00" ruby-1.9.2-head > foo.number_to_currency(101.00) => "$101.00" -
Fabian Schwahn
ok, I investigated a little further, and the bug only occurs if the default locale is set to :de .
So, if I set
config.i18n.default_locale = :de
in config/application.rb and execute the following in the console:
foo = ActionView::Base.new
foo.extend ActionView::Helpers::NumberHelper
foo.number_to_currency(101.00)
I am able to reproduce the bug with a fresh app.
Also happens with edge rails.
-
Fabian Schwahn
ok, some more information:
Apparently, if you set a locale different than :en, the number helpers stop working.
That is because the options are set as follows (in action_view/helpers/number_helper.rb):defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :default => {}) defaults = defaults.merge(currency) options = options.reverse_merge(defaults) unit = options.delete(:unit) format = options.delete(:format) begin value = number_with_precision(number, options.merge(:raise => true)) format.gsub(/%n/, value).gsub(/%u/, unit).html_safe</code>
So if I change the locale to anything else than the standard, and don't set the number formats up properly in config/locales/foo.yml, the number helpers crash, because unit, format and precision (in number_with_precision) are nil.
A solution would be to set the :en-locale as default here:
in the default-hash.defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) -
Santiago Pastorino
- Milestone cleared.
- State changed from new to open
- Assigned user set to Santiago Pastorino
Reproduced, working on a fix
-
Santiago Pastorino
Patch for master
-
Santiago Pastorino
new patch
-
José Valim
Pastorino, this still does not solve the problem. It should be something like this:
defaults = default_currency_values.merge(defaults).merge!(currency) -
Rafael Mendonça França
+1
This work fines for me. All tests pass.
-
Santiago Pastorino
The correct patch here
-
Repository
- State changed from open to committed
(from [c7e6777961239224e28171a46c9768db881c5506]) Added default currency values to NumberHelper and pass them to I18n.translate
[#4604 number_to_currency fails with "NoMethodError: undefined method `>=' for nil:N... state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/c7e6777961239224e28171a46c9768...
