This project is archived and is in readonly mode.
number_to_currency fails with "NoMethodError: undefined method `>=' for nil:NilClass"
Reported by Fabian Schwahn | May 15th, 2010 @ 04:55 PM | in 3.0.2
The title says it pretty much.
I use rvm, in this case ruby-1.8.7-p249. Seems to me like a ruby
problem.
Output from Rails console:
Loading development environment (Rails 3.0.0.beta3)
ruby-1.8.7-p249 > foo = ActionView::Base.new
ruby-1.8.7-p249 > foo.extend ActionView::Helpers::NumberHelper
ruby-1.8.7-p249 > foo.number_to_currency(101.00)
NoMethodError: undefined method `>=' for nil:NilClass
from /Users/fabianschwahn/.rvm/gems/ruby-1.8.7-p249@bluemoody-rails3/gems/activesupport-3.0.0.beta3/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /Users/fabianschwahn/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/rational.rb:526:in `**'
from /Users/fabianschwahn/.rvm/gems/ruby-1.8.7-p249@bluemoody-rails3/gems/actionpack-3.0.0.beta3/lib/action_view/helpers/number_helper.rb:285:in `number_with_precision'
from /Users/fabianschwahn/.rvm/gems/ruby-1.8.7-p249@bluemoody-rails3/gems/actionpack-3.0.0.beta3/lib/action_view/helpers/number_helper.rb:115:in `number_to_currency'
from (irb):3
Comments and changes to this ticket
-
Carlos Antonio da Silva May 15th, 2010 @ 05:06 PM
- 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 May 16th, 2010 @ 12:11 AM
- 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 May 16th, 2010 @ 12:12 AM
Fabian, can you try it using the latest Rails version from git?.
Thanks -
Enrico Bianco May 16th, 2010 @ 12:42 AM
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 May 16th, 2010 @ 12:42 AM
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 May 16th, 2010 @ 01:28 AM
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>
A solution would be to set the :en-locale as default here:
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
-
Santiago Pastorino May 16th, 2010 @ 02:09 AM
- Milestone cleared.
- State changed from new to open
- Assigned user set to Santiago Pastorino
Reproduced, working on a fix
-
José Valim May 16th, 2010 @ 10:04 PM
Pastorino, this still does not solve the problem. It should be something like this:
defaults = default_currency_values.merge(defaults).merge!(currency)
-
Repository May 17th, 2010 @ 04:40 PM
- State changed from open to committed
(from [c7e6777961239224e28171a46c9768db881c5506]) Added default currency values to NumberHelper and pass them to I18n.translate
[#4604 state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/c7e6777961239224e28171a46c9768... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to Low
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 4604 number_to_currency fails with "NoMethodError: undefined method `>=' for nil:NilClass" [#4604 state:committed]