Rails 3 - find_all_by_car_id 和 nil 对象
我收到此错误: [代码] 当你没有预料到的时候,你得到了一个 nil 对象! 您可能期望一个 Array 的实例。 评估 nil.each 时发生错误 [/code]
在控制器中:
@optionals = Car.find_all_by_car_id(1)
在视图中:
<% @optionals.each do |c| %>
<div><%= c.type %></div>
<% end %>
在表中 Car 是一行...所以我不明白,如何获得此错误消息...我尝试在谷歌上搜索,但不幸的是我仍然不知道不知道如何修复这个错误...
所以我很高兴得到每一个帮助!
编辑:表汽车中的car_id的值为1
I am getting this error:
[code]
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
[/code]
In controller:
@optionals = Car.find_all_by_car_id(1)
In view:
<% @optionals.each do |c| %>
<div><%= c.type %></div>
<% end %>
In the table Car is one row... so I don't understand, how is possible to getting this error message... I tried to search on google, but unfortunately I still don't know how to fix this error...
So I'll glad for each help!
EDIT: car_id in table Cars have the value 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在模板中添加一行,如下所示:
<%= @optionals.inspect %>
并确保它不为零。如果是,请检查日志以确保您调用的操作与您正在查看的模板匹配
Try adding a line in the template like so:
<%= @optionals.inspect %>
and make sure it's not nil.If it is, check the log to make sure the action that you're calling matches the template you're looking at