Generic-user-small Jamie Paulson 3 posts

So I’m running into some issues in the B1.1 edition…after making modifications to move the cart to the sidebar using partial templates (p 126), I get the following mess when I hit the store page:

================
NoMethodError in Store#index

Showing store/_cart.html.erb where line #5 raised:

You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.items

Extracted source (around line #5):

2: Your Cart
3:
4: <table>
5: <%= render(:partial => “cart_item”, :collection => cart.items) %>
6: <tr class="total-line">
7: <td colspan="2">
8: Total

Trace of template inclusion: /layouts/store.html.erb
===================

I’m staying pretty tight to the book (I think), so I’m kind of dumbfounded to hit an error. But it looks like maybe the store.html.erb doesn’t have an instance of @cart so is passing in nil. Maybe?

Still a newbie here so go easy on me…

 
Generic-user-small Jamie Paulson 3 posts

Hey remember the time I said I was staying tight to the book? Yeah, I was lying… Missed the changes to the store_controller.rb.

Disregard my post. Unless you want to make fun of the newbie now.

 
Samr_small_small Sam Ruby 111 posts

Line 5 looks like it might be missing an @ sign before cart.items. See _cart.html.erb

 
Generic-user-small Jamie Paulson 3 posts

Thanks for the response, Sam…but I think the book text is actually correct (it actually states that we can just use “cart” w/o the ”@”)...this is purely user error.

Working out of a PDF book apparently presents my brain some challenges in being able to read carefully. :-)

4 posts, 2 voices