Skip to content

Instantly share code, notes, and snippets.

@Solnse
Created November 7, 2011 07:42
Show Gist options
  • Save Solnse/1344406 to your computer and use it in GitHub Desktop.
Save Solnse/1344406 to your computer and use it in GitHub Desktop.
class FoodItemMenusController < ApplicationController
skip_before_filter :authorize
def food_list
@foods = FoodItem.all
@food_list = @foods.group_by { |t| t.category }
end
end
%h1 Listing food_item_menus
= @food_list.each do |category, food_items|
%p
= category
%ul
- food_items.each do |food|
%li
= food.name
# I'm simply trying to display all the records in the food_items table and group them by the field category (example: burgers, munchies, drinks)
class FoodItem < ActiveRecord::Base
has_many :menus, :through => :food_item_menus
has_many :food_item_menus
end
@Solnse
Copy link
Author

Solnse commented Nov 7, 2011

NoMethodError in Food_item_menus#index

Showing /home/chad/sites/mavericksaloon/app/views/food_item_menus/index.html.haml where line #5 raised:

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 #5):

2:
3: %h1 Listing food_item_menus
4:
5: = @food_list.each do |category, food_items|
6: %p
7: = category
8: %ul

Rails.root: /home/chad/sites/mavericksaloon
Application Trace | Framework Trace | Full Trace

app/views/food_item_menus/index.html.haml:5:in `_app_views_food_item_menus_index_html_haml___604926228_99384720'

Request

Parameters:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment