# Got NoMethodError although the instant variable exist

**URL:** <https://www.ruby-forum.com/t/got-nomethoderror-although-the-instant-variable-exist/145368>\
**Category:** Rails\
**Created:** [August 8, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/got-nomethoderror-although-the-instant-variable-exist/145368 "2008-08-08T14:06:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [August 8, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/got-nomethoderror-although-the-instant-variable-exist/145368/1 "2008-08-08T14:06:18Z")

</div>

Hi all,

When i access localhost:3000/home , got this NoMethodError

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

Extracted source (around line _#86_):

83:   
84:  
85:

  
86: \<%= hidden\_div\_if(@cart.items.empty?, :id =\> “cart”) %\>

87: \<%= render(:partial =\> “store/cart”, :object =\> @cart) %\>  
88:

  
89:

Here’s the controller’s action:  
def show\_page  
load\_data  
@cart = find\_cart  
@page = Page.find\_by\_name(params[:name])  
unless @page.is\_a? Page  
redirect\_to\_index(“Halaman tidak ada”)  
end  
end

Here’s the Application Trace:

app/views/layouts/store.rhtml:86:in  
`_run_rhtml_47app47views47layouts47store46rhtml' app/controllers/sessions_controller.rb:24:in`create’

sessions\_controller is a controller from RESTful authentication (which i  
was  
just installed, never got error like this before). I added @cart =  
find\_cart  
in its ‘new’ method. Here’s the find\_cart :

def find\_cart  
session[:cart] ||= Cart.new  
end

I’m wondering why i got the error?

Thanks,

Dida
