# Nil object problem in Rails 2.0.2

**URL:** <https://www.ruby-forum.com/t/nil-object-problem-in-rails-2-0-2/155030>\
**Category:** Rails\
**Created:** [December 6, 2008, 4:03pm UTC](https://www.ruby-forum.com/t/nil-object-problem-in-rails-2-0-2/155030 "2008-12-06T16:03:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 6, 2008, 4:03pm UTC](https://www.ruby-forum.com/t/nil-object-problem-in-rails-2-0-2/155030/1 "2008-12-06T16:03:01Z")

</div>

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

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

\<% end %\>

| 

_ **Author Name** _

 | 

_ **Age** _

 |
| \<%=h result.name %\> | \<%=h result.age %\> |

Cypray

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 6, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/nil-object-problem-in-rails-2-0-2/155030/2 "2008-12-06T16:39:09Z")

</div>

On Dec 6, 3:03 pm, Jay M. [removed\_email\_address@domain.invalid](mailto: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
