Skip to content

Instantly share code, notes, and snippets.

@et
Created February 17, 2012 21:55
Show Gist options
  • Select an option

  • Save et/1855686 to your computer and use it in GitHub Desktop.

Select an option

Save et/1855686 to your computer and use it in GitHub Desktop.
jQuery(function($) {
$('#search').keyup(_.debounce(function(e) {
e.preventDefault();
$.get($(this).data('search_contacts_path'), {
search : $(this).val(),
});
}, 200)
);
});
// debounce is from _underscore.js which delays the function call. This is optional.
class ContactsController
def search
respond_to do |format|
format.json {
@contacts = Contacts.search(params[:search]) # whatever your search stuff is
render :json => @contacts.to_json
}
end
end
end
<%= text_field_tag :search, params[:search],
:placeholder => "Search...",
'data-search_contacts_path' => search_contacts_path %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment