2013-07-19 80 views
0

我有一個相對簡單的Rails 4應用程序(運行在nitrous.io上),它做了一些特殊的事情。我有一個通過GET請求加載的表單,並且當表單頁面被加載時,rails服務器只呈現HTML,而沒有呈現任何資產。Rails服務器沒有爲某些頁面提供資源

Started GET "/posts/new" for 198.84.233.70 at 2013-07-19 06:40:16 +0000                         
Processing by PostsController#new as HTML                                
    Rendered posts/_comments_form.html.erb (4.1ms)                               
    Rendered posts/new.html.erb within layouts/application (22.5ms)                          
Completed 200 OK in 39ms (Views: 36.6ms | ActiveRecord: 0.0ms) 

結果是我的jQuery綁定(實際上沒有任何JavaScript)被執行。因此該頁面無法正常工作。

如果我重新加載頁面(通過單擊瀏覽器上的刷新按鈕),那麼所有的資產都得到了服務,所有的JavaScript都執行並且一切正常。

Completed 200 OK in 62ms (Views: 60.7ms | ActiveRecord: 0.0ms)                           


Started GET "/posts/new" for 198.84.233.70 at 2013-07-19 06:40:27 +0000                         
Processing by PostsController#new as HTML                                
    Rendered posts/_comments_form.html.erb (2.5ms)                               
    Rendered posts/new.html.erb within layouts/application (49.5ms)                          
Completed 200 OK in 62ms (Views: 60.7ms | ActiveRecord: 0.0ms) 
Started GET "/assets/application.css?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000                    
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000                 
Started GET "/assets/wines.css?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000 
Started GET "/assets/jquery.js?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000                     
Started GET "/assets/jquery_ujs.js?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000                    
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000 
Started GET "/assets/posts.js?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000                      
Started GET "/assets/application.js?body=1" for 198.84.233.70 at 2013-07-19 06:40:29 +0000 
+0

你的瀏覽器在第一頁上載什麼?你得到404或什麼? – phoet

+0

你在使用Turbolinks嗎?如果你是,你可能沒有綁定'page:change'。 – jvnill

+0

@jvnill是正確的。這個問題是由turbolinks造成的。我沒有意識到它是在默認情況下在Rails 4中啓用的。(@jvnill,讓它成爲答案,我會給你一個複選標記) –

回答

0

從上面的Rails 4

評論,Turbolinks被默認包含,所以你可能需要包括綁定page:change

相關問題