Error with show

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!

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

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.

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