Richlewis
Richlewis

Reputation: 15374

undefined method for nil class in rails 3

I keep getting the above error message when trying to view data from my model in my view (the index page of my controller)

my controller

 def index

 @recipe = Recipe.all

 end

my view

   <% @recipes.each do |r| %>
   <tr><td><%= r.dish_name %></td></tr>
    <% end %>

Im new to rails so maybe doing this completely wrong. Could someone also explain what the error means?

thanks

Upvotes: 0

Views: 119

Answers (1)

Richlewis
Richlewis

Reputation: 15374

Found my error. my controller needed to be

@recipes = Recipe.all

I didn’t pluralize my recipe object

Upvotes: 1

Related Questions