This project is archived and is in readonly mode.
Rails-3.0.3 - I18n.t does not treat 'number' as a string
Reported by James B. Byrne | December 22nd, 2010 @ 04:27 PM
In ActionView html.erb templates
I18n.t( 'number' ).strip raises
undefined method strip' for
#<Hash:0x2b946fb1ddc8>
As does:
I18n.t( "number" ).strip
And:
I18n.t( :number ).strip
app/views/clients/index.html.erb:23:in `_app_views_clients_index_html_erb___1793917816_23958288172140_0'
actionpack (3.0.3) lib/action_view/template.rb:135:in `send'
actionpack (3.0.3) lib/action_view/template.rb:135:in `render_without_comment'
activesupport (3.0.3) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.3) lib/action_view/template.rb:127:in `render_without_comment'
config/initializers/tattler.rb:4:in `render'
actionpack (3.0.3) lib/action_view/render/rendering.rb:59:in `_render_template'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.3) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.3) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:114:in `_render_template'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:108:in `render_to_body'
actionpack (3.0.3) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.3) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:101:in `render_to_string'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:92:in `render'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:40:in `render'
activesupport (3.0.3) lib/active_support/core_ext/benchmark.rb:5:in `ms'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.3) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.3) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.3) lib/action_controller/metal/mime_responds.rb:261:in `retrieve_response_from_mimes'
actionpack (3.0.3) lib/action_controller/metal/mime_responds.rb:192:in `call'
actionpack (3.0.3) lib/action_controller/metal/mime_responds.rb:192:in `respond_to'
app/controllers/clients_controller.rb:14:in `index'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:151:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.3) lib/active_support/callbacks.rb:450:in `_run__318314630__process_action__199225275__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `send'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:120:in `process'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.3) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:96:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:in `call'
activerecord (3.0.3) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.3) lib/rails/application.rb:168:in `call'
railties (3.0.3) lib/rails/application.rb:77:in `send'
railties (3.0.3) lib/rails/application.rb:77:in `method_missing'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:162:in `start'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:95:in `start'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:92:in `each'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:92:in `start'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:23:in `start'
/home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.1) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.1) lib/rack/server.rb:213:in `start'
railties (3.0.3) lib/rails/commands/server.rb:65:in `start'
railties (3.0.3) lib/rails/commands.rb:30
railties (3.0.3) lib/rails/commands.rb:27:in `tap'
railties (3.0.3) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
Comments and changes to this ticket
-
James B. Byrne December 22nd, 2010 @ 04:35 PM
Important condition:
This error only occurs if there is no entry in the translation file. If 'number' is not a key in config/locales/default/en.yml then the error is raised. If it is a key in the tranlation file then the error does not happen.
In other words, instead of a 'translation missing: en.number' string displayed in the view the error is raised.
-
Vijay Dev January 5th, 2011 @ 10:38 PM
A quick check showed that I18n.t("number") returns a Hash. So strip is obviously going to fail.
{:precision=>{:format=>{:delimiter=>""}}, :percentage=>{:format=>{:delimiter=>""}}, :format=>{:precision=>3, :delimiter=>",", :strip_insignificant_zeros=>false, :significant=>false, :separator=>"."}, :currency=>{:format=>{:precision=>2, :delimiter=>",", :format=>"%u%n", :strip_insignificant_zeros=>false, :significant=>false, :separator=>".", :unit=>"$"}}, :human=>{:decimal_units=>{:format=>"%n %u", :units=>{:thousand=>"Thousand", :trillion=>"Trillion", :quadrillion=>"Quadrillion", :billion=>"Billion", :million=>"Million", :unit=>""}}, :format=>{:precision=>3, :delimiter=>"", :strip_insignificant_zeros=>true, :significant=>true}, :storage_units=>{:format=>"%n %u", :units=>{:kb=>"KB", :tb=>"TB", :byte=>{:one=>"Byte", :other=>"Bytes"}, :gb=>"GB", :mb=>"MB"}}}}
May be "number" is a reserved word in I18n. Need to see if this is documented.
Edited by Rohit Arondekar for formatting.
-
Vijay Dev January 5th, 2011 @ 10:39 PM
Sorry about the bad formatting in the first line above. Please ignore the @'s.
-
Rohit Arondekar January 31st, 2011 @ 08:15 AM
- Importance changed from to Low
You are basically loading this hash: https://github.com/rails/rails/blob/master/actionpack/lib/action_vi...
Here is a use case:
I18n.t('number.currency.format.unit') => "$"
Have you defined a locale file which has
number:
? Could you please make a gist of that file and post the link here? -
José Valim January 31st, 2011 @ 08:28 AM
- State changed from new to invalid
This is because Rails adds the number key to your locale files. They contain how the number helpers should be behave. Overwriting it is not recommended and it is correct that it returns a hash.
-
James B. Byrne January 31st, 2011 @ 06:09 PM
Am I to understand then that if one uses BDD and develops a view requiring use of the string 'number' without previously providing a translation for it then the above failure is intentional and that it deliberately does not provide a translation missing notice?
Are there any other 'magic' keys using ordinary English words being added invisibly to locale files and likely to produce similar results?
Is there a reason that the common English word 'number' was chosen for this purpose and not some arbitrary string like rails_number_helper_code that might prove less likely to result in a collision?
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>