Created
April 1, 2010 18:14
-
-
Save jbynum/352170 to your computer and use it in GitHub Desktop.
This file contains 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
def search | |
@posts = Post.find(:all, :conditions => ['title LIKE ?', "#{params[:query]}%"], :order => "title") | |
results = [:query => "#{params[:query]}"] | |
suggestions = [] | |
@posts.each do |x| | |
suggestions << "#{x.title}" | |
end | |
results << {:suggestions => suggestions} | |
puts results | |
respond_to do |format| | |
format.json { render :json => results} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def search
@posts = Post.find(:all, :conditions => ['title LIKE ?', "#{params[:query]}%"], :order => "title")
results = {:query => params[:query], :suggestions => []}
@posts.each do |x|
results[:suggestions] << x.title
end
puts results
respond_to do |format|
format.json { render :json => results}
end
end