Searching using ajax:


#1

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:

<%= 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