簡體   English   中英

Rails 3.2:視圖中的路由助手在其他錯誤后在本地中斷

[英]Rails 3.2: Routing helpers in views break locally after other error

使用Rails 3.2在本地開發時,我會定期收到以下錯誤消息:

In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers

在一個非常簡單的link_to調用中,我的視圖拋出了這個錯誤,其中自動包含這些路由助手,不應該拋出這樣的錯誤。 我不認為錯誤發生在它所說的地方,但為了完整性,我將發布一個示例錯誤轉儲:

Completed 500 Internal Server Error in 233ms

ActionView::Template::Error (In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers):
    1: <%= form_tag products_path do %>

  app/views/layouts/_search_banner.html.erb:1:in `_app_views_layouts__search_banner_html_erb___3528929561490713150_70155778060240'
  app/views/pages/new.html.erb:1:in `_app_views_pages_new_html_erb__29715639072237790_70155789748980'

在它出現之前,我能夠正確查看我的所有頁面; 在它出現之后,剛剛加載的相同頁面失敗並出現同樣的錯誤。 一旦出現錯誤,修復它的唯一方法是退出並重啟我的本地rails服務器。 一旦我重新啟動服務器,錯誤就會消失,一切都恢復正常。

此外,此錯誤僅出現在我的計算機本地 - 代碼部署在Heroku上,並且在部署數月內未出現此錯誤,並且沒有其他團隊成員在相同代碼上運行時發現錯誤。 編輯:在相同代碼上運行的其他團隊成員確實看到相同的錯誤。

雖然這個錯誤有時會突然冒出而沒有明顯的原因,但我注意到了一些趨勢。 它經常出現在不同的錯誤之后。 當rails服務器空閑一段時間而不加載任何頁面時,它也更有可能出現。

編輯:更多信息Rails版本:3.2.13 Ruby版本:2.0.0

完整的堆棧跟蹤可以在這里找到

我通過編寫代碼在操作中拋出錯誤,向該操作發送請求,然后嘗試訪問應用程序中的任何其他頁面來實現錯誤。 有趣的是,我試圖使用的第一個錯誤是除零,這沒有產生錯誤。 接下來,我為Array []錯誤創建了一個Undefined Method,這導致了這里描述的錯誤。

編輯: Rails 2.3樣式插件的棄用警告當我部署到Heroku時,我收到以下錯誤:

DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0.
Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb.
See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released.
(called from <top (required)> at /tmp/build_175439d1-f385-43bd-bf52-ebcae817e70b/Rakefile:7)

MyApp::Application.load_tasks行上的Rakefile中拋出此錯誤。 我的vendor/plugin目錄中沒有任何文件。

奇...

嘗試替換它

<a href="<%= root_path %>" class="nav-link"><%= image_tag "image.svg", onerror: "this.src='image.png'" %></a>

有了這個

<%= link_to(image_tag("image.svg", onerror: "this.src='image.png'"), root_path, class: "nav-link") %>

據我所知,這是你的rails版本的一個問題。 請參閱有關此resque問題的評論: https//github.com/rails/rails/issues/11782#issuecomment-22222166

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM