我正在尝试将我的应用程序与设计进行国际化,但我在某些方面正在努力。我已经安装了i18n gem并创建了devise.pt-BR.yml
文件,并在application.rb
内写了
config.i18n.default_locale = :'pt-BR'
好的,但是当我尝试在我的应用程序中的任何内容时,我收到以下错误消息:
未定义的方法`default_locale ='为nil:NilClass
Rails.root:/ home / ubuntu / workspace / aqueleprojetoprivate / medicos 应用程序跟踪|框架跟踪|完整跟踪
应用程序/控制器/ application_controller.rb:8:在
中<class:ApplicationController>' app/controllers/application_controller.rb:1:in
” activesupport(4.2.4)lib / active_support / dependencies.rb:457:在load' activesupport (4.2.4) lib/active_support/dependencies.rb:457:in
块中 在load_file'activesupport(4.2.4)中 lib / active_support / dependencies.rb:647:innew_constants_in' activesupport (4.2.4) lib/active_support/dependencies.rb:456:in
load_file'activesupport(4.2.4) lib / active_support / dependencies.rb:354:inrequire_or_load' activesupport (4.2.4) lib/active_support/dependencies.rb:494:in
load_missing_constant'activesupport(4.2.4) lib / active_support / dependencies.rb:184:inconst_missing' app/controllers/home_controller.rb:1:in
' activesupport(4.2.4)lib / active_support / dependencies.rb:457:在load' activesupport (4.2.4) lib/active_support/dependencies.rb:457:in
块中 在load_file'activesupport(4.2.4)中 lib / active_support / dependencies.rb:647:innew_constants_in' activesupport (4.2.4) lib/active_support/dependencies.rb:456:in
load_file'activesupport(4.2.4) lib / active_support / dependencies.rb:354:inrequire_or_load' activesupport (4.2.4) lib/active_support/dependencies.rb:494:in
load_missing_constant'activesupport(4.2.4) lib / active_support / dependencies.rb:184:inconst_missing' activesupport (4.2.4) lib/active_support/inflector/methods.rb:261:in
const_get'activesupport(4.2.4) lib / active_support / inflector / methods.rb:261:在block in constantize' activesupport (4.2.4) lib/active_support/inflector/methods.rb:259:in
每个'activesupport(4.2.4)中 lib / active_support / inflector / methods.rb:259:ininject' activesupport (4.2.4) lib/active_support/inflector/methods.rb:259:in
constantize' activesupport(4.2.4)lib / active_support / dependencies.rb:566:inget' activesupport (4.2.4) lib/active_support/dependencies.rb:597:in
constantize'actionpack(4.2.4) lib / action_dispatch / routing / route_set.rb:72:incontroller_reference' actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:62:in
controller'actionpack(4.2.4) lib / action_dispatch / routing / route_set.rb:41:inserve' actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in
block in serve' actionpack(4.2.4)lib / action_dispatch / journey / router.rb:30:ineach' actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in
serve' actionpack(4.2.4)lib / action_dispatch / routing / route_set.rb:821:incall' warden (1.2.4) lib/warden/manager.rb:35:in
阻止通话' warden(1.2.4)lib / warden / manager.rb:34:incatch' warden (1.2.4) lib/warden/manager.rb:34:in
call' rack(1.6.4)lib / rack / etag.rb:24:incall' rack (1.6.4) lib/rack/conditionalget.rb:25:in
称'机架' (1.6.4)lib / rack / head.rb:13:incall' actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in
call' actionpack(4.2.4)lib / action_dispatch / middleware / flash.rb:260:incall' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in
上下文” rack(1.6.4)lib / rack / session / abstract / id.rb:220:incall' actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in
call' activerecord(4.2.4)lib / active_record / query_cache.rb:36:incall' activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in
call'activerecord(4.2.4)lib / active_record / migration.rb:377:incall' actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in
阻止通话' activesupport(4.2.4)lib / active_support / callbacks.rb:88:in__run_callbacks__' activesupport (4.2.4) lib/active_support/callbacks.rb:778:in
_ run_call_callbacks' activesupport(4.2.4)lib / active_support / callbacks.rb:81:inrun_callbacks' actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in
调用'actionpack (4.2.4)lib / action_dispatch / middleware / reloader.rb:73:incall' actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in
call'actionpack(4.2.4) lib / action_dispatch / middleware / debug_exceptions.rb:17:incall' web-console (2.2.1) lib/web_console/middleware.rb:31:in
call' actionpack(4.2.4) lib / action_dispatch / middleware / show_exceptions.rb:30:incall' railties (4.2.4) lib/rails/rack/logger.rb:38:in
call_app'railties (4.2.4)lib / rails / rack / logger.rb:20:在block in call' activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in
块中标记为' activesupport(4.2.4)lib / active_support / tagged_logging.rb:26:intagged' activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in
标记为'railties(4.2.4) lib / rails / rack / logger.rb:20:incall' actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in
call'rack(1.6.4) lib / rack / methodoverride.rb:22:在call' rack (1.6.4) lib/rack/runtime.rb:18:in
调用'activesupport(4.2.4) LIB / active_support /缓存/策略/ local_cache_middleware.rb:28:在call' rack (1.6.4) lib/rack/lock.rb:17:in
调用'actionpack(4.2.4) lib / action_dispatch / middleware / static.rb:116:在call' rack (1.6.4) lib/rack/sendfile.rb:113:in
调用'railties(4.2.4) lib / rails / engine.rb:518:在call' railties (4.2.4) lib/rails/application.rb:165:in
呼叫'机架(1.6.4) lib / rack / lock.rb:17:incall' rack (1.6.4) lib/rack/content_length.rb:15:in
call'rack(1.6.4) lib / rack / handler / webrick.rb:88:inservice' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in
service' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in {_ 1}}阻止在start_thread'
我该如何解决?
答案 0 :(得分:1)
看起来你的Rails是版本4.2。
如果是这种情况,则不应使用config.i18n
,而应使用I18n
见here:
# in config/initializers/locale.rb
# tell the I18n library where to find your translations
I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
# set default locale to something other than :en
I18n.default_locale = :pt