In my controller I do:
@categories = Category.all
for i in @[email protected]
@allposts.push(Post.where(:Category => i))
end
In views(haml) i do
<% @allposts.each do |posts, slots| %>
<% @slots.each do |post| %>
<%= post.Title %>
<% end %>
<% end %>
And i see this error:
undefined method `each' for nil:NilClass on @slots.each do |post|.
Thank you in advance.
@slots? As inside the block you created as|posts, slots|...Categoryis associated with modelPostwith1-M relationshipthen you can simply loop over@categorieslike@categories.each do |category|category.poststo get all the posts associated with a given category. Why to make multidimensional arrays and complicate it?