# Nil object where not expected

**URL:** <https://www.ruby-forum.com/t/nil-object-where-not-expected/111720>\
**Category:** Rails\
**Created:** [August 10, 2007, 3:21am UTC](https://www.ruby-forum.com/t/nil-object-where-not-expected/111720 "2007-08-10T03:21:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [August 10, 2007, 3:21am UTC](https://www.ruby-forum.com/t/nil-object-where-not-expected/111720/1 "2007-08-10T03:21:24Z")

</div>

trying to pass a collection of authors using  
\<%= render :partial =\> ‘author’, :collection =\> @authors %\>

\_authors.rhtml file has

 \<%= link\_to author.name, :action =\> 'show', :id =\> @author %\> \<%= link\_to 'Edit', :action =\> 'edit', :id =\> author %\> \<%= button\_to 'Delete', {:action =\> 'destroy', :id =\> author}, :confirm =\> "Are you sure you want to delete author #{author.name}?" %\> 

in  
def index  
@authors = Author.find(:all)  
@page\_title = ‘Listing authors’  
end

and I’m getting

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

Extracted source (around line #2):

1:

  
2: \<%= link\_to @post.author.name, :action =\> ‘show’, :id =\>  
@author %\>  
3: \<%= link\_to ‘Edit’, :action =\> ‘edit’, :id =\> author %\>  
4:   
5: \<%= button\_to ‘Delete’, {:action =\> ‘destroy’, :id =\> author},

any ides what I may be doing wrong here ?

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [August 10, 2007, 3:54am UTC](https://www.ruby-forum.com/t/nil-object-where-not-expected/111720/2 "2007-08-10T03:54:26Z")

</div>

Dave wrote:

> ```
> <%= button_to 'Delete', {:action => 'destroy', :id => author},
> 
> ```
> 
> 3:
> 
> \<%= link\_to ‘Edit’, :action =\> ‘edit’, :id =\> author %\>  
> 4:   
> 5: \<%= button\_to ‘Delete’, {:action =\> ‘destroy’, :id =\> author},
> 
> any ides what I may be doing wrong here ?
> 
> Where is @post being set?
> 
> –  
> Michael W.

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [August 10, 2007, 4:24am UTC](https://www.ruby-forum.com/t/nil-object-where-not-expected/111720/3 "2007-08-10T04:24:28Z")

</div>

@post is not being set, I’m a rails newbie @post was one of the  
solutions I found on google, but none are solving my problem this the  
error I get

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

Extracted source (around line #2):

1:

  
2: \<%= link\_to author.name, :action =\> ‘show’, :id =\> @author  
%\>  
3: \<%= link\_to ‘Edit’, :action =\> ‘edit’, :id =\> author %\>  
4:   
5: \<%= button\_to ‘Delete’, {:action =\> ‘destroy’, :id =\> author},

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [August 11, 2007, 4:55am UTC](https://www.ruby-forum.com/t/nil-object-where-not-expected/111720/4 "2007-08-11T04:55:59Z")

</div>

Thanks for the help got it working…

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [August 10, 2007, 8:23am UTC](https://www.ruby-forum.com/t/nil-object-where-not-expected/111720/5 "2007-08-10T08:23:41Z")

</div>

Hi!

If the partial is called ‘author’, then the file must be called  
‘\_author.rhtml’

Andrey
