28 Jun 2013, 11:01
Generic-user-small

zofia sunderland (2 posts)

Hello,

I use the fourth edition of your book and when i put this command in the terminal:

curl –silent http://localhost:3000/products/3/who_bought.atom

i get very long printout where i find, among other things:

<header>
  <h1>
    NoMethodError in
    Products#who_bought
  </h1>
</header>

<div id="container">
  <p>
    Showing <i>/home/bartek/Pulpit/CQ_RoR/work/depot/app/views/products/who_bought.atom.builder</i> where line <b>#2</b> raised:
  </p>
  

undefined method `title' for nil:NilClass ~~~ ~~~

I did all i should according to the chapter and i dont know what is going on. Please help.

Zosia

29 Jun 2013, 12:27
Samr_small_pragsmall

Sam Ruby (584 posts)

Line 2 reads:

feed.title "Who bought #{@product.title}"

So it looks like @product is nil. It is set in the controller thus:

@product = Product.find(params[:id])

So it looke like you don’t have a product with an id of 3? Try going to http://localhost:3000/products and clicking on one of the show links and observing the id in the url.

01 Jul 2013, 10:07
Generic-user-small

zofia sunderland (2 posts)

@product is set in the controller’s method who_bought and all the ids in url after clicking show are correct (I checked all three products)…

02 Jul 2013, 00:51
Samr_small_pragsmall

Sam Ruby (584 posts)

Automated regression tests for this chapter are posted online.

Please double check your code for typos. Instance variables don’t need to be declared and default to nil, so if either the assignment or the reference to @product is mispelled, the result will be exactly as you describe.

  You must be logged in to comment