# Error with show

**URL:** <https://www.ruby-forum.com/t/error-with-show/94326>\
**Category:** Rails\
**Created:** [April 28, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/error-with-show/94326 "2006-04-28T21:15:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 28, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/error-with-show/94326/1 "2006-04-28T21:15:10Z")

</div>

Hello everyone, I have a problem while opening something like  
/main/show/1

Here is the template for show.rhtml

\<% for name in @names %\>

## \<%= name.full\_name %\>

\<% end %\>

And here is the code specific to the show on the main\_controller.rb

def show  
name = Name.find(params[:id])  
end

And here is the error im getting.

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.each

Any idea on what the problem might be? Any help would be great, thanks!

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 28, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/error-with-show/94326/2 "2006-04-28T21:48:03Z")

</div>

Guest wrote:

> The error occured while evaluating nil.each
> 
> Any idea on what the problem might be? Any help would be great, thanks!

In your template you reference @names. In your controller you do not  
define @names, so you get a nil object error - the @names object doesn’t  
exist.

You probably want to cut the first and last lines of your show.rhtml  
since you are only showing one name each time, not the whole array of  
names.

–

Ray

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 28, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/error-with-show/94326/3 "2006-04-28T22:02:29Z")

</div>

Ray B. wrote:

> You probably want to cut the first and last lines of your show.rhtml  
> since you are only showing one name each time, not the whole array of  
> names.

Alright I tried that and got an error:

undefined local variable or local method ‘name’

I have no idea why Im having so much trouble with this, it seems so  
simple yet I cant get it to work.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [October 3, 2006, 5:11am UTC](https://www.ruby-forum.com/t/error-with-show/94326/4 "2006-10-03T05:11:29Z")

</div>

Guest wrote:

> Ray B. wrote:
> 
> > You probably want to cut the first and last lines of your show.rhtml  
> > since you are only showing one name each time, not the whole array of  
> > names.
> 
> Alright I tried that and got an error:
> 
> undefined local variable or local method ‘name’
> 
> I have no idea why Im having so much trouble with this, it seems so  
> simple yet I cant get it to work.

I have this same problem, and it doesn’t seem like it’s been answered  
here. Does anyone have an idea of why this doesn’t work? I can’t seem  
to get rid of the scaffolding column loop system so I can just show  
certain elements as I wish and style them as I wish. Any ideas?

Thanks,  
Dave
