Skip to content

Instantly share code, notes, and snippets.

@joeljunstrom
Created May 17, 2010 14:35
Show Gist options
  • Save joeljunstrom/403834 to your computer and use it in GitHub Desktop.
Save joeljunstrom/403834 to your computer and use it in GitHub Desktop.
# Allow the metal piece to run in isolation
require File.expand_path('../../../config/environment', __FILE__) unless defined?(Rails)
class AutoComplete
def self.call(env)
if env["PATH_INFO"] =~ /^\/auto_complete\/tags/
params = Rack::Request.new(env).params
sql = "SELECT name
FROM tags
WHERE name LIKE #{ActiveRecord::Base.connection.quote(params['q']+'%')}
LIMIT 10"
[200, {"Content-Type" => "application/json"},
[ActiveRecord::Base.connection.select_values(sql).to_json]
]
[404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment