Created
May 17, 2010 14:35
-
-
Save joeljunstrom/403834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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