开发者

Rails 3 - find_all_by_car_id and nil object

开发者 https://www.devze.com 2023-03-12 00:58 出处:网络
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.

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

精彩评论

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