2015-11-05 31 views
0

我在Rails項目中得到了'undefined method'[]'for nil:NilClass'錯誤。應用程序中的Rails NoMethodError#index

這個錯誤來自下面一行在我app/views/layouts/application.html.erb

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 

我曾嘗試刪除該線,並且錯誤消失,但JavaScript文件無法加載。

我正在使用rails 4.2.4,並且一直在開發這個項目幾個星期,這是我第一次遇到這個錯誤。服務器在兩天內正常工作。文件app/views/layouts/application.html.erb根本沒有改變。

這裏是日誌:

Started GET "/" for ::1 at 2015-11-05 17:08:04 +0800 
    ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" 
Processing by ApplicationController#index as HTML 
    Rendered application/index.html.erb within layouts/application (0.8ms) 
Completed 500 Internal Server Error in 842ms (ActiveRecord: 0.0ms) 

ActionView::Template::Error (undefined method `[]' for nil:NilClass): 
    3: <head> 
    4: <title>Guildmasters</title> 
    5: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    6: <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
    7: <%= csrf_meta_tags %> 
    8: </head> 
    9: <body> 
    app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___1282808844249308017_70187111969200' 


    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (11.3ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.0ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (56.2ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.5ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.4ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.4ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (42.1ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.6ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.4ms) 
    Rendered /usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (91.5ms) 
+0

你能提供你被觸發的網址嗎? – 2015-11-05 08:48:54

+0

嗨,這是[http:// localhost:3000 /](http:// localhost:3000 /) – zycuber

+0

好吧,我認爲你應該發佈你的路線的根網址。我不認爲在應用程序控制器中沒有運行或調用對象。 – 2015-11-05 08:58:49

回答

0

對不起,我只是想出了這個錯誤。我正在使用EmberJS,並且我在views文件夾中放置了一個hbs文件,該文件夾應該位於templates中。在我移動了hbs文件後,錯誤消失了。