# Searching using ajax:

**URL:** <https://www.ruby-forum.com/t/searching-using-ajax/155115>\
**Category:** Rails\
**Created:** [December 8, 2008, 9:44am UTC](https://www.ruby-forum.com/t/searching-using-ajax/155115 "2008-12-08T09:44:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreekanth.G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@sreekanth.G](https://www.ruby-forum.com/u/sreekanth.G)\
**Post date:** [December 8, 2008, 9:44am UTC](https://www.ruby-forum.com/t/searching-using-ajax/155115/1 "2008-12-08T09:44:07Z")

</div>

hi i have a table called Streams with columns  
name,resolution,codecname,framerate.  
i have tags to the table entries if streams.like 1920x1080,aac,mpeg2…

now i have to search the table entries for tag entered in the search  
box.  
once i enter the tag name in the search box entry i m getting errors  
like:

Unknown action  
No action responded to get\_results

can help me in this issue?

to do that i have added below codes in;

1)index.html.erb

Search:

![](https://test.ruby-forum.com/images/indicator.gif)

\<%= observe\_field 'search\_form', :frequency =\> 0.5, :update =\> 'results', :url =\> { :controller =\> 'streams', :action=\> 'get\_results' }, :with =\> "'search\_text=' + escape(value)", :loading =\> "document.getElementById('spinner').style.display='inline'", :loaded =\> "document.getElementById('spinner').style.display='none'" %\>

2)streams\_controller.rb

def get\_results  
if request.xhr?  
if params[‘search\_text’].strip.length \> 0  
terms = params[‘search\_text’].split.collect do |word|  
“%#{word.downcase}%”  
end  
#@streams = Stream.find(  
# :all,  
# :conditions =\> [( ["(LOWER(name) LIKE ?)"] \* terms.size  
).join(" AND "),\* terms.flatten])

```
    #addded for listing the streams with a tag assigned

    @streams = Stream.find_tagged_with(params[:search_text])
    #@streams = Stream.find_tagged_with(params[:terms])
  end
  render :partial => "search"
else
  redirect_to :action => "index"
end

```

end

3)in layouts :streams.html.erb

 Streams \<%= javascript\_include\_tag :defaults %\> \<%= yield %\> 

4)created \_search.html.erb for results:

\<% if @streams %\>

 \<% for stream in @streams %\> - \<%= h(stream.name) %\> 
 \<% end %\> 
\<% end %\>

thanks  
srikanth
