简体   繁体   English

Rails 3.2:视图中的路由助手在其他错误后在本地中断

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

When developing locally using Rails 3.2, I periodically receive the following error message: 使用Rails 3.2在本地开发时,我会定期收到以下错误消息:

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

This error is thrown from my views in a very simple link_to call, where these routing helpers are automatically included and should not throw such an error. 在一个非常简单的link_to调用中,我的视图抛出了这个错误,其中自动包含这些路由助手,不应该抛出这样的错误。 I don't think the error is occurring where it says, but I'll post an example error dump for completeness' sake: 我不认为错误发生在它所说的地方,但为了完整性,我将发布一个示例错误转储:

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'

Before it appears, I am able to properly view all of my pages; 在它出现之前,我能够正确查看我的所有页面; after it appears, the same pages that had just loaded successfully fail with that same error. 在它出现之后,刚刚加载的相同页面失败并出现同样的错误。 Once the error appears, the only way to fix it is to exit and restart my local rails server. 一旦出现错误,修复它的唯一方法是退出并重启我的本地rails服务器。 As soon as I restart my server the error disappears and everything goes back to working normally. 一旦我重新启动服务器,错误就会消失,一切都恢复正常。

Also, this error only appears locally on my computer - the code is deployed on Heroku and this error has not appeared in months of deployment, and no other team members operating on the same code have seen the error. 此外,此错误仅出现在我的计算机本地 - 代码部署在Heroku上,并且在部署数月内未出现此错误,并且没有其他团队成员在相同代码上运行时发现错误。 EDIT: other team members operating on the same code do see the same error. 编辑:在相同代码上运行的其他团队成员确实看到相同的错误。

Although this error sometimes pops up out of nowhere with no apparent cause, there are a couple of trends I have noticed. 虽然这个错误有时会突然冒出而没有明显的原因,但我注意到了一些趋势。 It frequently appears immediately after a different error. 它经常出现在不同的错误之后。 It also is more likely to appear when the rails server has been idle for some time without loading any pages. 当rails服务器空闲一段时间而不加载任何页面时,它也更有可能出现。

EDIT: More Information Rails version: 3.2.13 Ruby version: 2.0.0 编辑:更多信息Rails版本:3.2.13 Ruby版本:2.0.0

The full stack trace can be found here 完整的堆栈跟踪可以在这里找到

I achieved the error by writing code to throw an error in an action, sending a request to that action, then attempting to access any other page in the application. 我通过编写代码在操作中抛出错误,向该操作发送请求,然后尝试访问应用程序中的任何其他页面来实现错误。 Interestingly, the first error that I attempted to use was a division by zero, which did not create the error. 有趣的是,我试图使用的第一个错误是除零,这没有产生错误。 Next, I created a Undefined Method for Array[] error, which resulted in the one described here. 接下来,我为Array []错误创建了一个Undefined Method,这导致了这里描述的错误。

EDIT: Deprecation Warning for Rails 2.3-style plugins When I deploy to Heroku, I get the following error: 编辑: 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)

This error is thrown in my Rakefile on the line MyApp::Application.load_tasks . MyApp::Application.load_tasks行上的Rakefile中抛出此错误。 I do not have any files in my vendor/plugin directory. 我的vendor/plugin目录中没有任何文件。

Odd... 奇...

Try replacing this 尝试替换它

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

with this 有了这个

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

as far as i can see it's an issue with your rails version. 据我所知,这是你的rails版本的一个问题。 see the comments on this resque issue: https://github.com/rails/rails/issues/11782#issuecomment-22222166 请参阅有关此resque问题的评论: https//github.com/rails/rails/issues/11782#issuecomment-22222166

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM