I have the following problem:
In Rails I have two Objects: Categories and Items One category has many items and one item belongs to one category.
Okay. There are no problems. But now, I want to display all existing categories in a sidebar on every page in my project.
I tried to do display them like:
<div class="sidebar">
<% @categories.each do |category| %>
<p><%= link_to category.title, category %></p>
<% end %>
</div>
My root controller is categories. On my starting page the code above will work without any problems.
But when I click on a category I get the following exception:
*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*
Extracted source (around line #2):
2: <% @categories.each do |category| %>
How can I fix this problem?
Sorry for my bad English!