[英]Error in my live app when navigating admin interface
When I navigate to a certain resource in the admin interface for my app I get a status 500 error. 当我在应用程序的管理界面中导航到某个资源时,出现状态500错误。 Why might this be?
为什么会这样呢?
Here is from my logs: 这是我的日志:
2011-06-16T21:33:35+00:00 app[web.1]: Started GET "/admin/timeline_events" for 151.205.162.106 at 2011-06-16 14:33:35 -0700
2011-06-16T21:33:35+00:00 app[web.1]:
2011-06-16T21:33:35+00:00 app[web.1]: NoMethodError (undefined method `map' for nil:NilClass):
How would I find where map
is in my app? 我如何找到
map
在我的应用程序中的位置?
OK, so I think it's this code in my application helper that might be causing this 好的,所以我认为可能是应用程序帮助程序中的这段代码导致了
def render_timeline(events, title)
events.map do |event|
render(:partial => "timeline_events/#{event.event_type}", :locals => {:event => event, :title => title})
end.join.html_safe
end
The code basically renders different partials depending on what type of event it is to create a feed. 该代码基本上根据创建提要的事件类型来呈现不同的部分。
It looks like you're calling the method but passing nil
as the events
argument. 看起来您正在调用方法,但是将
nil
作为events
参数传递。
Make sure that when there are no events to be rendered, you pass in an empty array instead of nil
. 确保在没有要呈现的事件时,传入一个空数组而不是
nil
。
You can catch this in the body of the method by adding: 您可以通过添加以下内容在方法的主体中捕获该信息:
events ||= []
as the first line, or you can use default arguments: 作为第一行,或者您可以使用默认参数:
def render_timeline(events = [], title)
or you can just change how you generate the events
argument so it never returns nil
. 或者您可以更改
events
参数的生成方式,使其永远不会返回nil
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.