繁体   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