没有物体通过轨道2.3?

时间:2011-10-14 05:37:20

标签: jquery ruby-on-rails ajax

我正在加载一个下拉列表来选择场地和该值过去以加载一个模态对话框。然后我收到了以下错误。

find_new

Showing app/views/layouts/_dia_venu_search.html.erb where line #5 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map

Extracted source (around line #5):

2: <span style="text-align: right>
3: 
4: <% form_tag "/calendar/dia_venue_view" do %>
5:  <%= collection_select("venue", "venue_id", @venues , :id, :place, {:prompt => true}) %>
6: <%end%>
7: </span>
8: <span style="text-align: right">

Trace of template inclusion: app/views/layouts/_dia_venue_search.html.erb

RAILS_ROOT: D:/final2011_10_13
Application Trace | Framework Trace | Full Trace

C:/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/form_options_helper.rb:327:in `options_from_collection_for_select'
C:/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/form_options_helper.rb:543:in `to_collection_select_tag'
C:/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/form_options_helper.rb:162:in `collection_select'
D:/final2011_10_13/app/views/layouts/_dia_venu_search.html.erb:5:in `_run_erb_app47views47layouts47_dia_venu_search46html46erb_locals_dia_venu_search_object'
D:/final2011_10_13/app/views/layouts/_dia_venu_search.html.erb:4:in `_run_erb_app47views47layouts47_dia_venu_search46html46erb_locals_dia_venu_search_object'
D:/final2011_10_13/app/views/layouts/_dia_venue_search.html.erb:15:in `_run_erb_app47views47layouts47_dia_venue_search46html46erb_locals_dia_venue_search_object'
D:/final2011_10_13/app/views/layouts/_dia_venue_search.html.erb:2:in `_run_erb_app47views47layouts47_dia_venue_search46html46erb_locals_dia_venue_search_object'
D:/final2011_10_13/app/controllers/events_controller.rb:196:in `find_new'

这是我的_dia_venu_search.html.erb代码:

<span style="text-align: right">
<span style="text-align: right>

<% form_tag "/calendar/dia_venue_view" do %>
<%= collection_select("venue", "venue_id", @venues , :id, :place, {:prompt => true}) %>
<%end%>
</span>
<span style="text-align: right">
<%= submit_tag "search" %>
</span>
</span>

为什么我会收到此错误?有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

检查@venues的值。它没有?它们可能导致collection_select引发该错误。

答案 1 :(得分:0)

你的@venues回归零。 collection_select期待一个数组。 试试这个

<% @venues = [] unless @venues %>
<%= collection_select("venue", "venue_id", @venues , :id, :place, {:prompt => true}) %>