I've create a partial (views/cart/_cart.html.erb) for my applications shopping cart. I'm rendering it in only in my views/layouts/application.html.erb file. But when I run it I'm getting a NoMethodError on every page other than the views/cart/_cart.index.erb, which I suspect is because it shares the same controller as the partial being rendered.
I've been looking everywhere for an answer & believe it has something to do with how I'm passing variables when rendering the partial, I'll really appreciate it if someone can have a look?
All code can be found here: https://github.com/rossmc/topsnowboards
My code for my partial (views/cart/_cart.html.erb) begins:
<% @cart = cart%>
<h1>Your Cart</h1>
<% if @cart.empty? %>
<p>There is nothing in your shopping Cart</p>
<% end %>
<% total = 0 %>
<!-- More code displaying the rest of the cart omitted for brevity
The partial is rendered in views/layouts/application.html.erb with:
<%= render :partial => "/cart/cart", :locals => { :cart => @cart }
The error message Rails is throwing back at me when I run it is:
NoMethodError in Site#home
Showing Server Side/PROJ-Server Side/app/views/cart/_cart.html.erb where line #5 raised:
undefined method `empty?' for nil:NilClass
Extracted source (around line #5):
2:
3: <h1>Your Cart</h1>
4:
5: <% if @cart.empty? %>
6: <p>There is nothing in your shopping Cart</p>
7: <% end %>
8: