Forum: Ruby on Rails nil object problem in Rails 2.0.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jay M. (Guest)
on 2008-12-06 17:03
I think my problem is that Rails is not seeing the private method "def
author_age" that is holding the result of the query.
Do I suppose to put this in the Controller and not in the model?
How does the object @results get known to Rails?



Here is my code:

class Author < ActiveRecord::Base

has_many :books

def author_age
    @results = Author.find :all, :conditions => ["age = ?",
params[:authors]]
     end
end



I have this on view\authors\show.html

<table border="1">
 <tr>
 <td width="20%"><p align="center"><i><b>Author Name</b></i></td>
 <td width="20%"><p align="center"><i><b>Age</b></i></td>
 </tr>


 <% @results.each do |result| %>

 <tr>

 <td><%=h result.name %></td>
 <td><%=h result.age %></td>
 </tr>
<% end %>
</table>

Cypray
Frederick C. (Guest)
on 2008-12-06 17:39
(Received via mailing list)
On Dec 6, 3:03 pm, Jay M. <removed_email_address@domain.invalid> wrote:
> I think my problem is that Rails is not seeing the private method "def
> author_age" that is holding the result of the query.

It's not a private method.

> Do I suppose to put this in the Controller and not in the model?
> How does the object @results get known to Rails?

You're only showing a portion of your code, but the view sees instance
variables of the corresponding controller, not of models.

Fred
This topic is locked and can not be replied to.