nil object passing in rails 2.3?
I am loading a drop down list to select venue and that value passe to load a modal dialog box.Then I got following error.
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_开发者_JS百科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'
here is my _dia_venu_search.html.erb code:
<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>
why did I get this error? can anybody help me?
Your @venues is returning nil. collection_select expect an array. try this
<% @venues = [] unless @venues %>
<%= collection_select("venue", "venue_id", @venues , :id, :place, {:prompt => true}) %>
check the value of @venues. Is it nil? They may cause collection_select to raise that error.
精彩评论