You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auto_completes_controller.rb 770B

123456789101112131415161718192021222324252627
  1. class AutoCompletesController < ApplicationController
  2. before_filter :find_project
  3. def issues
  4. @issues = []
  5. q = params[:q].to_s
  6. query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
  7. if q.match(/^\d+$/)
  8. @issues << query.visible.find_by_id(q.to_i)
  9. end
  10. unless q.blank?
  11. @issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
  12. end
  13. @issues.compact!
  14. render :layout => false
  15. end
  16. private
  17. def find_project
  18. project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
  19. @project = Project.find(project_id)
  20. rescue ActiveRecord::RecordNotFound
  21. render_404
  22. end
  23. end