# Simple search in ror

**URL:** <https://www.ruby-forum.com/t/simple-search-in-ror/190354>\
**Category:** Rails\
**Created:** [June 18, 2010, 11:51am UTC](https://www.ruby-forum.com/t/simple-search-in-ror/190354 "2010-06-18T11:51:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![punkaruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/49beb7/32.png) [@punkaruby](https://www.ruby-forum.com/u/punkaruby)\
**Post date:** [June 18, 2010, 11:51am UTC](https://www.ruby-forum.com/t/simple-search-in-ror/190354/1 "2010-06-18T11:51:03Z")

</div>

Hi,  
i need to implement a simple text function for the app i dev now.

1- the form in app/views/layouts

\<% form\_tag({:controller =\> “teachers”, :action =\> “search”}, :method =\>  
“get”) do %\>  
\<%= text\_field\_tag :query, nil, :id =\> “search-text” %\>  
\<%= submit\_tag(“GO”, :id =\> “search-submit”) %\>  
\<% end %\>

2- the search method in teacher\_controller.rb

def search  
session[:query] = params[:query].strip if params[:query]

```
if session[:query]
  @teachers = Teacher.find(:all, :conditions => ["materie LIKE ?",

```

“%#{session[:query]}%”], :order =\> “cognome ASC”)  
end  
end

3- the page for the result in app/view/teachers/search.html.erb

## Teachers found
  
\<% if searchresults.length == 0 %\> 

No teacher found...

\<% elsif params[:query] == "" %\> 

Insert a term, please.

\<% else %\>
\<% for teacher in searchresults %\> - \<%= link\_to teacher.cognome , teacher\_url(:id =\> teacher.id)%\>
\<% end %\>
\<% end %\>

But when I push the search button the page goes to the show function…

Heeeeeeelp !!!

Many many thanks to all who…
