diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d451215d..e94aac3a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -124,8 +124,9 @@ class ApplicationController < ActionController::Base end - def for_autocomplete(coll) - coll.map {|item| "#{item.name}|#{item.id}"}.join("\n") + def for_autocomplete(coll, substr) + filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase} + return filtered.map {|item| "#{item.name}|#{item.id}"}.join("\n") end # Uses RedCloth to transform text using either Textile or Markdown Need to diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index bd6b900f..d6492211 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -22,7 +22,7 @@ class ContextsController < ApplicationController format.rss &render_contexts_rss_feed format.atom &render_contexts_atom_feed format.text { render :action => 'index', :layout => false, :content_type => Mime::TEXT } - format.autocomplete { render :text => for_autocomplete(@active_contexts + @hidden_contexts)} + format.autocomplete { render :text => for_autocomplete(@active_contexts + @hidden_contexts, params[:q])} end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 454a7e6e..2baffa1a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -26,7 +26,7 @@ class ProjectsController < ApplicationController format.rss &render_rss_feed format.atom &render_atom_feed format.text &render_text_feed - format.autocomplete { render :text => for_autocomplete(@projects) } + format.autocomplete { render :text => for_autocomplete(@projects, params[:q]) } end end end diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index e55298b9..4ad8446e 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -530,7 +530,7 @@ class TodosController < ApplicationController def tags @tags = Tag.all respond_to do |format| - format.autocomplete { render :text => for_autocomplete(@tags) } + format.autocomplete { render :text => for_autocomplete(@tags, params[:q]) } end end