small medium large xlarge

Generic-user-small
20 May 2008, 02:09
phil newman (2 posts)

I was working through Chapter 12 (I read the preface but wanted to forge ahead.) Now suddenly my store returns:

` NoMethodError in Store#index

Showing layouts/store.html.erb where line #18 raised:

You have a nil object when you didn’t expect it! The error occurred while evaluating nil.items Extracted source (around line #18):

15: <div id="columns"> 16: <div id="side"> 17: 18: <% hidden_div_if(@cart.items.empty?, :id => “cart”) do %> 19: <%= render(:partial => “cart”, :object => @cart) %> 20: <% end %> 21: RAILS_ROOT: /Users/pnewman/work/depot4

Application Trace | Framework Trace | Full Trace app/views/layouts/store.html.erb:18:in _run_erb_47app47views47layouts47store46html46erb'

How do I trace this?

Samr_small_pragsmall
20 May 2008, 02:29
Sam Ruby (634 posts)

What that is saying is that @cart is nil. The correct version of that file should look something like: “app/controllers/store_controller.rb”:http://media.pragprog.com/titles/rails3/code/depot_q/app/controllers/store_controller.rb

Note the before_filter line near the top and the “@cart =” addition to find_cart. These changes were described on page 175 in iteration F4 in B1.1.

Generic-user-small
20 May 2008, 09:04
phil newman (2 posts)

Thank you! I missed the last change in find_cart. Great book - great tutorial!!!

You must be logged in to comment