Created
August 26, 2010 21:18
-
-
Save denzuko/552279 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
# Notes from http://www.railsonwave.com/2007/2/21/tutorial-opensearch-with-rails-1-2-render-json | |
# html snippet | |
# <link rel="search" type="application/opensearchdescription+xml" title="Search a City" href="http://YOUR-ADDRESS/search.xml" /> | |
# Codes SQL - http://www.railsonwave.com/assets/2007/2/20/city_codes.sql.zip | |
class SearchController < ApplicationController | |
def suggest | |
@codes ||= cities(:all) | |
@res ||= @codes.map{ |c| c.cityname } | |
render :json=>[params[:city],@res].to_json | |
end | |
def index | |
end | |
def you_choose | |
@city = cities(:first) | |
end | |
private | |
def cities(sorting = :all, limit = 10) | |
City.find(sorting, :conditions=>["cityname LIKE ?",params[:city]+"%"], | |
:limit=>limit, | |
:group=>"cityname", | |
:order=>"cityname") | |
end | |
end | |
file search.xml << END | |
<?xml version="1.0" encoding="UTF-8"?> | |
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" | |
xmlns:moz="http://www.mozilla.org/2006/browser/search/"> | |
<ShortName>US cities lookup</ShortName> | |
<Description>Us cities lookup</Description> | |
<InputEncoding>UTF-8</InputEncoding> | |
<Image height="16" width="16" type="image/x-icon">URL-TO-AN-ICON-FILE</Image> | |
<Url type="application/x-suggestions+json" template="http://YOUR-ADDRESS/search/suggest?city={searchTerms}"/> | |
<Url type="text/html" method="GET" template="http://YOUR-ADDRESS/search/you_choose/{searchTerms}"/> | |
</OpenSearchDescription> | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment