开发者

Rails 3 - find_all_by_car_id and nil object

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 开发者_JAVA技巧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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜