view app/controllers/auto_completes_controller.rb @ 156:9d2c8317d42f feature_75

* Add method to WS API controller to permit Embedded plugin to be switched on or off for a project (via /sys/projects/<id>/embedded.xml?key=<key>&enable={0,1})
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 27 Jan 2011 14:53:41 +0000
parents 1d32c0a0efbf
children af80e5618e9b
line wrap: on
line source
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