Skip to content

Instantly share code, notes, and snippets.

@jbynum
Created April 1, 2010 18:14
Show Gist options
  • Save jbynum/352170 to your computer and use it in GitHub Desktop.
Save jbynum/352170 to your computer and use it in GitHub Desktop.
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
@bradfordw
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment