# Newbie having problem with search function

**URL:** <https://www.ruby-forum.com/t/newbie-having-problem-with-search-function/89610>\
**Category:** Rails\
**Created:** [March 21, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/newbie-having-problem-with-search-function/89610 "2007-03-21T16:57:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![billy\_am](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@billy\_am](https://www.ruby-forum.com/u/billy_am)\
**Post date:** [March 21, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/newbie-having-problem-with-search-function/89610/1 "2007-03-21T16:57:49Z")

</div>

Hi Guys ,

```
           I am a newbie to rails so forgive me if this has been

```

answered before. I am currently doing an inventory management project  
on RoR and got 3 tables , goods , customers and staff. I used scaffold  
to generate all of them.

```
           I just generated a new scaffold called search and I

```

need to search values from all 3 tables. i am using the steps from  
this site ,

[http://wiki.rubyonrails.org/rails/pages/HowToImplementSearch](http://wiki.rubyonrails.org/rails/pages/HowToImplementSearch)

The only change is from Person/people to Book/books .But I keep  
getting this error

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.each

Can someone help? The places where I put the codes are below ,

def search  
query = params[:q]  
@people = Person.find(:all, :conditions =\> [“name = ?”, query])  
end

is in search\_controller.rb

the codes for view are in view/search/index.rhtml and search.rhtml.  
Thank you so much!!

regards  
billy

---

<div class="post-metadata">

**Author:** ![billy\_am](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@billy\_am](https://www.ruby-forum.com/u/billy_am)\
**Post date:** [March 21, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/newbie-having-problem-with-search-function/89610/2 "2007-03-21T17:55:56Z")

</div>

billy am wrote:

> You might have expected an instance of Array.
> 
> the codes for view are in view/search/index.rhtml and search.rhtml.  
> Thank you so much!!
> 
> regards  
> billy

Hi Billy,

Can you check for typos? As the message suggests, it seems that one of  
the arrays you are evaluating in the view does not actually have any  
data in it. Perhaps, you have a typo like @book instead of @books or  
something in your view… would be worth checking, in my opinion.

Does Rails show you the code where the error occurs? Could you post  
that?

Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![billy\_am](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@billy\_am](https://www.ruby-forum.com/u/billy_am)\
**Post date:** [March 22, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/newbie-having-problem-with-search-function/89610/3 "2007-03-22T16:33:51Z")

</div>

The case is closed 😛 Thanks to Mohit for the help!

regards  
billy
