Created
February 17, 2012 21:55
-
-
Save et/1855686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= 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