small medium large xlarge

13 Jun 2008, 07:14
Mark McCollum (2 posts)

Hi, I am working my way through the book, and have just completed iteration A4. I can load the index page with no problem, but when I click the link to create a new product I get the following error:

NoMethodError in Products#new

Showing layouts/products.html.erb where line #16 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 #16):

13: <h1>Listing products</h1> 14:
15: <table cellpadding="5" cellspacing="0"> 16: <% for product in @products %>

I also get similar errors when using the other links on the page. Any idea what is causing this?

13 Jun 2008, 14:35
Sam Ruby (634 posts)

The lines you quoted look like they are from “app/views/products/index.html.erb”: and not from “app/views/layouts/products.html.erb”:

By any chance, did some of these lines get added (appended?) to the end of the layout? Check both files against the links provided above.

16 Jun 2008, 00:27
Mark McCollum (2 posts)

You hit it right on the nose. I must have pasted into the wrong file. Thanks!

You must be logged in to comment