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



使用 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 服务器空闲一段时间而没有加载任何页面时,它也更有可能出现。

编辑:更多信息导轨版本:3.2.13拼音版本:2.0.0

完整的堆栈跟踪可以在这里找到

我通过编写代码在操作中抛出错误,向该操作发送请求,然后尝试访问应用程序中的任何其他页面来实现错误。有趣的是,我尝试使用的第一个错误是除以零,这不会产生错误。接下来,我创建了一个 Array[] 错误的未定义方法,这导致了这里描述的方法。

编辑: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)

此错误在我的 Rakefile 第 MyApp::Application.load_tasks 行中抛出。我的vendor/plugin目录中没有任何文件。

我所知,这是您的 Rails 版本的问题。 请参阅有关此问题的评论: https://github.com/rails/rails/issues/11782#issuecomment-22222166

奇数...

尝试替换此

<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") %>

最新更新