Rails list method

S

Sven Schott

I have setup rails and it works nicely. I have used the scaffolding to
get started(brilliant) but when I get to replacing the list method, I
get an error. I have gone through the tutorials thoroughly but I cannot
find anything wrong. It could be something simple as I do not know much
about rails. The error I get is the following:

NoMethodError in Friends#list

Showing /friends/list.rhtml where line #10 raised undefined method
`each' for nil:NilClass
7: <h1>Friends#list</h1>
8: <p>
9: <b>Names of all the people</b>
10: <% @people.each do |@item| %>
11: Name: <%= person.name %><br/>
12: <% end %>
13: <%=link_to "List", :action => "list" %>


Show template trace

Request

Parameters: None

Show session dump

Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}

Show template parameters


The code is:

def list
@person = Person.find_all
end

And the view is:

<b>Names of all the people</b>
<% @people.each do |@item| %>
Name: <%= person.name %><br/>
<% end %>


I have tried several styles of code. Using for instead of each in the
view;Using the list method from the scaffolding straight. But every
time I get this response. The data in the MySQL database is pretty
simple. What am I doing wrong? When I saw the nilClass I thought that
person was not being correctly passed on but because my knowledge of
rails is minimal, I'm pretty much stuck.

I would appreciate any help or comments.

Regards

Sven Schott
 
S

Sven Schott

Thank you David. I knew it had to be stupidity on my part. It now reads:

<b>Names of all the people</b>
<% @person.each do |@item| %>
Name: <%= @item.name %><br/>
<% end %>

That work swell.

Once again, thanks.

Regards

Sven Schott

Hi --

10: <% @people.each do |@item| %>
[...]

def list
@person = Person.find_all

Shouldn't that be @people ?


David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,162
Messages
2,570,893
Members
47,432
Latest member
GTRNorbert

Latest Threads

Top