undefined方法`default_locale ='代表nil:NilClass

时间:2016-01-24 17:24:18

标签: ruby-on-rails ruby-on-rails-3 devise

我正在尝试将我的应用程序与设计进行国际化,但我在某些方面正在努力。我已经安装了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:in new_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:in require_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:in const_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:in new_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:in require_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:in const_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:in inject' activesupport (4.2.4) lib/active_support/inflector/methods.rb:259:in constantize'   activesupport(4.2.4)lib / active_support / dependencies.rb:566:in get' activesupport (4.2.4) lib/active_support/dependencies.rb:597:in constantize'actionpack(4.2.4)   lib / action_dispatch / routing / route_set.rb:72:in controller_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:in serve' 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:in each' 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:in   call' warden (1.2.4) lib/warden/manager.rb:35:in阻止通话'   warden(1.2.4)lib / warden / manager.rb:34:in catch' warden (1.2.4) lib/warden/manager.rb:34:in call' rack(1.6.4)lib / rack / etag.rb:24:in   call' rack (1.6.4) lib/rack/conditionalget.rb:25:in称'机架'   (1.6.4)lib / rack / head.rb:13:in call' 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:in   call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in上下文”   rack(1.6.4)lib / rack / session / abstract / id.rb:220:in call' actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in call'   activerecord(4.2.4)lib / active_record / query_cache.rb:36:in call' 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:in   call' 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:in   run_callbacks' actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in调用'actionpack   (4.2.4)lib / action_dispatch / middleware / reloader.rb:73:in call' 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:in call' 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:in call' 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:in   tagged' activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in标记为'railties(4.2.4)   lib / rails / rack / logger.rb:20:in call' 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:in call' rack (1.6.4) lib/rack/content_length.rb:15:in call'rack(1.6.4)   lib / rack / handler / webrick.rb:88:in service' /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'

我该如何解决?

1 个答案:

答案 0 :(得分:1)

看起来你的Rails是版本4.2。

如果是这种情况,则不应使用config.i18n,而应使用I18nhere

# 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