Rails ActionView::Template::Error (wrong argument type Integer (expected Proc)) 求解

miclle · 2017年01月19日 · 最后由 flowerwrong 回复于 2017年01月19日 · 2352 次阅读

日志信息:

I, [2017-01-19T10:34:09.480151 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92] Started GET "/kodo/manual/console-quickstart" for 180.168.57.238 at 2017-01-19 10:34:09 +0800
I, [2017-01-19T10:34:09.481607 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92] Processing by ArticlesController#show as HTML
I, [2017-01-19T10:34:09.481724 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]   Parameters: {"space"=>"kodo", "category"=>"manual", "slug"=>"console-quickstart"}
I, [2017-01-19T10:34:09.492332 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]   Rendering articles/show.html.erb within layouts/application
I, [2017-01-19T10:34:09.667666 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]   Rendered articles/_sidebar.html.erb (174.8ms)
I, [2017-01-19T10:34:09.667793 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]   Rendered articles/show.html.erb within layouts/application (175.3ms)
I, [2017-01-19T10:34:09.667978 #663]  INFO -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92] Completed 500 Internal Server Error in 186ms
F, [2017-01-19T10:34:09.669235 #663] FATAL -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]
F, [2017-01-19T10:34:09.669295 #663] FATAL -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92] ActionView::Template::Error (wrong argument type Integer (expected Proc)):
F, [2017-01-19T10:34:09.669456 #663] FATAL -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]      5:   <div class="doctree">
[cb67d56d-ea60-4a42-8476-2f6105bc6f92]      6:     <%= article_tree(@space, "manual") %>
[cb67d56d-ea60-4a42-8476-2f6105bc6f92]      7:     <%= article_tree(@space, "api") %>
[cb67d56d-ea60-4a42-8476-2f6105bc6f92]      8:     <%= article_tree(@space, "sdk") %>
[cb67d56d-ea60-4a42-8476-2f6105bc6f92]      9:     <%= article_tree(@space, "tools") %>
[cb67d56d-ea60-4a42-8476-2f6105bc6f92]     10:     <%= article_tree(@space, "kb") %>
[cb67d56d-ea60-4a42-8476-2f6105bc6f92]     11:     <%= article_tree(@space, "glossary") %>
F, [2017-01-19T10:34:09.669514 #663] FATAL -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92]
F, [2017-01-19T10:34:09.669564 #663] FATAL -- : [cb67d56d-ea60-4a42-8476-2f6105bc6f92] app/helpers/application_helper.rb:55:in `tree'
[cb67d56d-ea60-4a42-8476-2f6105bc6f92] app/helpers/application_helper.rb:30:in `block in article_tree'
[cb67d56d-ea60-4a42-8476-2f6105bc6f92] app/helpers/application_helper.rb:28:in `article_tree'
[cb67d56d-ea60-4a42-8476-2f6105bc6f92] app/views/articles/_sidebar.html.erb:8:in `_app_views_articles__sidebar_html_erb__1127305977640810156_14232180'
[cb67d56d-ea60-4a42-8476-2f6105bc6f92] app/views/articles/show.html.erb:2:in `_app_views_articles_show_html_erb__3239522526908293125_18031560'

article_tree helper 方法

def article_tree(space, category = nil)
  if category.nil?
    articles = Article.roots.where(space: space)
  else
    articles = Article.roots.where(space: space, category: "article-#{category}")
  end

  if articles.blank?
    return
  end

  html = '<ul>'

  if !category.nil?
    html += '''
      <li class="branch">
        <a class="node-title category" href="javascript:;">
          <span>'+ Article::CATES[category] +'</span>
          <i class="icon fa"></i>
        </a>
        <ol>
    '''
  end

  articles.each do |article|
    html += render :partial => 'articles/tree', :locals => {:article => article}
  end

  if !category.nil?
    html += '</ol></li>'
  end

  html += '</ul>'
  raw html
end

articles/_tree.html.erb

<li class="<%= article.children.blank? ? 'leaf' : 'branch' -%>">
  <%= link_to article_path(space: article.space, category: article.category_short, slug: article.slug),
    class: "node-title #{ is_active?(article.slug) }" do %>
    <%= content_tag :span, article.locale_title %>
    <i class="icon fa fa-2"></i>
  <% end %>

  <% unless article.children.blank? %>
  <ol>
    <% article.children.each do |article| %>
      <%= render :partial => "articles/tree", :locals => {:article => article} %>
    <% end %>
  </ol>
  <% end %>
</li>

系统环境:

ruby 2.4.0p0
rails: 5.0.1
mongoid: 6.0.3

上面这个异常是偶发的,相同的请求 10 次可能出现 1 次,看最近的日志里面 1208 个请求里面出现了 140 次

好久不用 Rails 了,实在是没查出来问题原因 😭

https://github.com/DatabaseCleaner/database_cleaner/issues/466

降到 2.3.1 后解决了

(wrong argument type Integer (expected Proc)) 从字面上看,是不是参数不应该是 integer 型的,应该传进个 Proc 型的进去

#1 楼 @gakki 上面这个异常是偶发的,相同的请求 10 次可能出现 1 次

给下行号吧,都不知道 30,28 是哪一行。

miclle 关闭了讨论。 01月19日 11:37
需要 登录 后方可回复, 如果你还没有账号请 注册新账号