summaryrefslogtreecommitdiffstats
path: root/app/controllers/auto_completes_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/auto_completes_controller.rb')
-rw-r--r--app/controllers/auto_completes_controller.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb
new file mode 100644
index 000000000..1438106f6
--- /dev/null
+++ b/app/controllers/auto_completes_controller.rb
@@ -0,0 +1,25 @@
+class AutoCompletesController < ApplicationController
+ before_filter :find_project
+
+ def issues
+ @issues = []
+ q = params[:q].to_s
+ if q.match(/^\d+$/)
+ @issues << @project.issues.visible.find_by_id(q.to_i)
+ end
+ unless q.blank?
+ @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
+ end
+ render :layout => false
+ end
+
+ private
+
+ def find_project
+ project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
+ @project = Project.find(project_id)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+end