我正在开发一个Web应用程序(很好地尝试)在Ruby on Rails上。Ruby和Nil对象
我在index.html.erb部分呈现
<%= render :partial => "houses/index", :locals => @houses %>
index.html.erb加载当用户点击我的域名的根。这部分原因,此错误:
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.each
提取的源周围线8
5: <th>Washrooms</th>
6: </tr>
7:
8: <% @houses.each do |house| %>
9: <tr>
10: <td><%=h house.short_desc %></td>
11: <td><%=h house.bedrooms %></td>
模板包含的跟踪:应用程序/视图/家庭/ index.html.erb
所有我想在我的主页上显示5个房屋(index.html.erb)
我错过了什么让它起作用?
非常感谢
编辑:
NoMethodError主页#指数
展示应用/视图/房/ _index.html.erb其中第10行中提出:
当你没有想到它时,你有一个零对象! 您可能预期了Array的一个实例。而评估nil.each
发生 错误提取的源(围绕线#10):
7:洗手间 8: 9: 10:<%@ houses.each做|房子| %> 11: 12:<%= H house.short_desc%> 13:<%= H house.bedrooms%>
模板包含的跟踪:应用/视图/家/ index.html.erb
无关的答案,但难道不:收集=> @houses更合适? – 2009-11-11 22:34:41