summaryrefslogtreecommitdiffstats
path: root/app/controllers/auto_completes_controller.rb
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-08-17 15:03:58 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-08-17 15:03:58 +0000
commit3eff27344b0bef7703ba248d0a2312bfca95c182 (patch)
treeeefbe2247a166db315bf278b75300a959df00936 /app/controllers/auto_completes_controller.rb
parente63acb70ca82d0c62476c92bbe815330ee01ad93 (diff)
downloadredmine-3eff27344b0bef7703ba248d0a2312bfca95c182.tar.gz
redmine-3eff27344b0bef7703ba248d0a2312bfca95c182.zip
Refactor: move IssuesController#auto_complete to a new controller. #4382
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3945 e93f8b46-1217-0410-a6f0-8f06a7374b81
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