【发布时间】:2014-01-08 18:49:42
【问题描述】:
我正在通过 ajax 加载我的应用程序的一部分,我已经全部设置好了,我点击了上面设置了 remote: true 的链接,请求了正确的 URL,但在控制台中我收到了 500 错误并且以下:
在 2014-01-08 18:46:08 开始 GET "/coasters?page=18" for 127.0.0.1 +0000 CoastersController#index 作为 JS 参数处理:{"page"=>"18"} 渲染共享/_fact-bar.html.erb (0.9ms) 渲染 Coasters/index.html.erb (1.5ms) Completed 500 Internal Server Error in 3毫秒
NoMethodError - 未定义的方法
each_with_index' for nil:NilClass:_app_views_shared__fact_bar_html_erb__2012545158101504906_70360428754860' actionpack (3.2.12) lib/action_view/template.rb:145:in
app/views/shared/_fact-bar.html.erb:6:inblock in render' activesupport (3.2.12) lib/active_support/notifications.rb:125:ininstrument' actionpack (3.2.12) lib/action_view/template.rb:143:in `render'
我不太确定是什么部分导致了错误。有帮助吗?
事实栏部分:
<div class="facts bar bar--white-wave">
<div class="container--padded">
<h1>Facts & Statistics</h1>
<ul class="fact-circle-container">
<% circleCount = 1 %>
<% @stats.each_with_index do |stat, i| %>
<% if stat[:active] == 1 then %>
<li>
<% if stat[:link] then %>
<a href="<%= stat[:link] %>">
<% end %>
<div class="fact-circle fact-circle--<%= circleCount %>" data-number="20">
<div class="inner">
<span><%= stat[:value] %></span>
</div>
</div>
<% if stat[:link] then %>
</a>
<% end %>
<h3 class="fact-circle__title"><%= stat[:name] %></h3>
</li>
<% circleCount = circleCount + 1 %>
<% end %>
<% end %>
</ul>
</div>
</div>
【问题讨论】:
-
你能告诉我们fact-bar.html.erb部分吗?看起来您可能正在对非 Enumerable 类型的东西调用 each_with_index。
-
您在
_fact-bar中调用each_with_index,部分内容是nil。 -
你把所有的东西都写在那里了:文件 app/views/shared/_fact-bar.html.erb,第 6 行。你试图在返回 nil 的变量上调用 each_with_index。
-
将事实栏部分添加到我的 OP。我不知道为什么这会导致错误,因为该部分与我正在 ajaxing 的部分无关?
-
需要显示设置它的控制器操作,也许在第 18 页上没有更多结果?
标签: ruby-on-rails ajax