Created
April 2, 2009 02:27
-
-
Save mileszs/88992 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
class LegislatorsController < ApplicationController | |
layout :choose_layout | |
def search | |
setup_search(legislators_path(:u => params[:u])) | |
end | |
def bm_search | |
setup_search(bm_legislators_path(:u => params[:u])) | |
end | |
def index | |
if address = !params[:address].blank? && params[:address] || !params[:zip].blank? && params[:zip] | |
location = Geocoding::get(address).first | |
cookies[:zip], cookies['lat'], cookie['long'] = location.postal_code.to_s, location.latitude.to_s, location.longitude.to_s | |
end | |
lat, long = cookies['lat'], cookies['long'] | |
#we should also store the lat and long for the user link. | |
#just so we can see if people move? Or cheat? | |
@link = Link.find_or_create_by_url(params[:u], :title => params[:title]) | |
@client = Client.find(params[:client]) | |
@user = @link.user_links.create({ | |
:ip => request.remote_ip, | |
:client_id => @client, | |
:lat => lat, | |
:long => long, | |
}) | |
@results = Legislator.all_for( :latitude => lat , :longitude => long ) | |
end | |
alias :bm_index, :index | |
private | |
def setup_search(redirect_path) | |
@link = Link.find_or_create_by_url(params[:u], :title => params[:title]) | |
if !cookies["zip"].blank? | |
redirect_to redirect_path | |
end | |
end | |
def choose_layout | |
['bm_search', 'bm_index'].include?(action_name) ? 'bookmarklet' : 'application' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment