2011-10-14 60 views
0

我正在加載一個下拉列表來選擇場地,該值通過加載模態對話框。然後我得到以下錯誤。nil對象在rails 2.3中傳遞?

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> 

爲什麼我得到這個錯誤?有誰能夠幫助我?

回答

0

您的@venues正在返回零。 collection_select期望一個數組。 試試這個

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

現在我沒有收到任何錯誤。但它沒有得到下拉列表的位置...... :( – Rosh

+0

嘗試放置一個調試器並檢查@venues正在返回。 – Mahesh

0

檢查@venues的值。它是零嗎?他們可能會導致collection_select引發該錯誤。