Forum: Ruby on Rails searching using ajax:

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
sreekanth.G (Guest)
on 2008-12-08 10:44
(Received via mailing list)
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: <input type="text" id="search_form" name="search" />

<img id="spinner" src="/images/indicator.gif" style="display: none;" />
<div id="results"></div>
<%= 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

<html>
  <head>
    <title>Streams</title>
    <%= javascript_include_tag :defaults %>
  </head>
  <body>
    <%= yield  %>
  </body>
</html>

4)created _search.html.erb for results:

<% if @streams %>
  <ul>
    <% for stream in @streams %>
      <li>
      <%= h(stream.name) %>
      </li>
    <% end %>
  </ul>
<% end %>

thanks
srikanth
This topic is locked and can not be replied to.