Skip to content

Instantly share code, notes, and snippets.

@amerine
Created February 17, 2009 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amerine/65612 to your computer and use it in GitHub Desktop.
Save amerine/65612 to your computer and use it in GitHub Desktop.
#View
<label for="searchtext">Search for a specific fighter:</label>
<%= text_field_with_auto_complete :fighter, :contains, { :size => 15 }, :skip_style => true -%>
<p>Search Results:</p>
<div id="fighter_name_results"></div>
#Controller
def auto_complete_for_fighter_contains
fighter_query = params[:fighter][:contains]
@fighters = Fighter.find(:all, :conditions => ["first_name LIKE ? or last_name LIKE ? or ring_name LIKE ?",fighter_query,fighter_query,fighter_query]) unless fighter_query.blank?
render :partial => "_fighter_name_search_pane"
end
#Partial
<ul class="autocomplete_list">
<% for fighter in @fighters %>
<li class="autocomplete_item"><%= link_to "#{fighter.first_name} #{fighter.last_name}", {:controller => :main, :action => :fighter, :id => fighter.id} %>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment