[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails list method

Sven Schott

11/29/2004 1:02:00 AM

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



2 Answers

dblack

11/29/2004 1:13:00 AM

0

Sven Schott

11/29/2004 1:25:00 AM

0

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

On 29/11/2004, at 12:12 PM, David A. Black wrote:

> Hi --
>
> On Mon, 29 Nov 2004, Sven Schott wrote:
>
>> 10: <% @people.each do |@item| %>
>
> [...]
>
>> def list
>> @person = Person.find_all
>
> Shouldn't that be @people ?
>
>
> David
>
> --
> David A. Black
> dblack@wobblini.net
>
>
>