search index page:
<%= form_tag nil, { :id => 'search_form'} %>
Search Tutorials
<%= text_field 'tutorial', 'title' %>
<%= end_form_tag %>
<%= observe_form :search_form, :frequency => 0.5, :update => 'tutorial', :url => { :action => 'search_ajax' }%>
Search Controller:
class SearchController < ApplicationController
def index
end
def search_ajax
@tutorials = Tutorial.find(:all, :conditions => ["title LIKE ?", "%#{params[:tutorial][:title]}%"])
render :layout => false
end
end
Search AJAX page:
<% for tutorial in @tutorials %>
<%= link_to tutorial.title, :controller => 'tutorial', :action => "show", :id => tutorial.id %>
posted in: <%= tutorial.category %> by <%= tutorial.username %> on <%= tutorial.date %>
<% end %>