# NoMethodError

**URL:** <https://www.ruby-forum.com/t/nomethoderror/91886>\
**Category:** Rails\
**Created:** [April 13, 2007, 2:56am UTC](https://www.ruby-forum.com/t/nomethoderror/91886 "2007-04-13T02:56:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 13, 2007, 2:56am UTC](https://www.ruby-forum.com/t/nomethoderror/91886/1 "2007-04-13T02:56:30Z")

</div>

I am receiving this error messagek

NoMethodError in Story#index

Showing app/views/story/index.rhtml where line #2 raised:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.size  
Extracted source (around line #2):

1:

## 2: \<%= “Showing #{ pluralize(@stories.size, ‘story’, ‘stories’) }” %\> 3:
  
4: \<%= render :partial =\> ‘story’, :collection =\> @stories %\>

Any help would be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 13, 2007, 5:19am UTC](https://www.ruby-forum.com/t/nomethoderror/91886/2 "2007-04-13T05:19:28Z")

</div>

Zkidd wrote:

> I am receiving this error messagek
> 
> NoMethodError in Story#index
> 
> Showing app/views/story/index.rhtml where line #2 raised:
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.size  
> Extracted source (around line #2):
> 
> 1:
> 
> ## 2: \<%= “Showing #{ pluralize(@stories.size, ‘story’, ‘stories’) }” %\> 3:
>   
> 4: \<%= render :partial =\> ‘story’, :collection =\> @stories %\>
> 
> Any help would be appreciated. Thanks.

Your @stories instance variable is nil, meaning it doesn’t exist or has  
no data in it. In your story controller index method, are you creating  
the instance variable called @stories?

---

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 13, 2007, 5:50am UTC](https://www.ruby-forum.com/t/nomethoderror/91886/3 "2007-04-13T05:50:42Z")

</div>

Zkidd wrote:

> 1:
> 
> ## 2: \<%= “Showing #{ pluralize(@stories.size, ‘story’, ‘stories’) }” %\> 3:
>   
> 4: \<%= render :partial =\> ‘story’, :collection =\> @stories %\>
> 
> Any help would be appreciated. Thanks.

@stories is nil. Make sure the query or whatever object that variable is  
pointing at is not nil.

–  
Michael W.
