Rails 4:启动rails服务器时出错 - 可能是locales问题?

时间:2013-09-08 10:15:18

标签: ruby-on-rails locale

我试图添加this guide上列出的time_zone_select语言环境,但在此过程中搞乱了我的rails应用程序。 当我使用rails s启动rails服务器时,出现以下错误:

/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated': Rails::Application
::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007f946155b930 @paths=["
/Users/DaniG2k/Documents/Aptana Studio 3 Workspace/MyApp/config/routes.rb"], @route_sets=[#<ActionDispatch::Routing::RouteSet:0x007f9464045150>]> (RuntimeError
)
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
        from /Users/DaniG2k/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /Users/DaniG2k/Documents/Aptana Studio 3 Workspace/MyApp/config/environment.rb:5:in `<top (required)>'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
        from /Users/DaniG2k/Documents/Aptana Studio 3 Workspace/MyApp/config.ru:3:in `block in <main>'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
        from /Users/DaniG2k/Documents/Aptana Studio 3 Workspace/MyApp/config.ru:in `new'
        from /Users/DaniG2k/Documents/Aptana Studio 3 Workspace/MyApp/config.ru:in `<main>'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/server.rb:48:in `app'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/server.rb:75:in `start'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
        from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

基本上,我认为这归结为我的语言环境的一个问题,但我无法理解它是什么。 我在行<。p>之前的routes.rb中添加了binding.pry

get '' => redirect("/#{I18n.default_locale}")
  scope "/:locale", locale: /#{I18n.available_locales.join("|")}/ do

我注意到,从那里,如果我做I18n.available_locales我得到:

NoMethodError: undefined method `deep_symbolize_keys' for "国際日付変更線":String
from /Users/DaniG2k/.rvm/gems/ruby-2.0.0-p247/gems/i18n-0.6.5/lib/i18n/backend/simple.rb:34:in `store_translations'

我尝试删除我的语言环境.yml文件中的所有双引号,但这似乎没有解决问题。

这是我当前的语言环境结构:

config/
  locales/
    defaults/
      en.yml
      ja.yml
    timezones/
      ja.yml
    devise.en.yml
    en.yml
    ja.yml

似乎失败的locales文件是:

ja:
  timezones:
    "International Date Line West": "国際日付変更線"
    "Midway Island": "ミッドウェイ諸島"
    "American Samoa": "米領サモア"
    "Samoa": "サモア"
    "Hawaii": "ハワイ"
    "Alaska": "アラスカ"
    "Pacific Time (US & Canada)": "太平洋標準時 (アメリカ・カナダ)"
    etc...

但似乎没有奇怪的空间或任何东西,所以它应该正常工作。 我的app / models /目录中也有这个,不确定它是否会对失败消息产生影响:

#app/models/i18n_time_zone.rb
class I18nTimeZone < ActiveSupport::TimeZone
  def to_s
    translated_name = I18n.t(name, :scope => :timezones, :default => name)
    "(GMT#{formatted_offset}) #{translated_name}"
  end
end

在修复之前我甚至无法启动我的rails控制台或服务器... -_- 我有什么想法可以解决这个问题吗?

提前致谢!

1 个答案:

答案 0 :(得分:3)

手动重新缩进整个时区yml文件似乎解决了这个问题。