Innocent Akhidenor
Innocent Akhidenor

Reputation: 135

creating a twitter like auto suggest search box in rails

please those anyone know how to create a twitter or facebook like auto-suggest search box? i have been trying to implement this for a while now...here is some code i got from enter link description here.

 <div class="search_index">


 <div id = "testsearch">
 <%=render :partial => 'search'%> // partial where the updated search elements will appear from 
 </div>

<%=form_tag(search_path,:method=>'get',:remote=>true) do%>

   <%=text_field_tag :search%>
   <%= submit_tag "search" ,:name=>nil%>

<%end%>

<%= set_focus_to_id 'search' %>  // I have a helper "set_focus_to_id"



<script> // small javascript file :)

 document.observe("dom:loaded", function() {   // ensures the page is loaded first
 new Form.Element.Observer(                    // Observes the text_field_tag every 2     seconds
  'search',
   2,
   respondToChange                         //refrences the function in the Layout      
   )                                         // on a change in search calls   respondToChange
  });

  </script>

  </div>

at the tag i have

 <script>
 function respondToChange() {
 $('search').up('form').submit()            // The ".up finds the form in the DOM"
 };
 </script>

The code Doesn't seem to be working,it doesnt even respond

please does any one know how to implement this functionality in a more efficient way

i really need help with this

Upvotes: 0

Views: 675

Answers (1)

Nate-Wilkins
Nate-Wilkins

Reputation: 5502

A good option is to use a pre-existing Script:

  1. http://tweet.seaofclouds.com/
  2. http://jquery.malsup.com/twitter/

They created their own and it has a few features worth considering. Or even using.

Upvotes: 2

Related Questions