Skip to content

Commit

Permalink
Add explicit country code
Browse files Browse the repository at this point in the history
  • Loading branch information
famulus committed Jul 7, 2011
1 parent edaba82 commit 4660d04
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -13,7 +13,7 @@ gem 'haml'
gem "geokit-rails3", "~> 0.1.3"
gem 'hirb'
gem 'dynamic_form'
gem 'rake', '0.8.7'
gem 'rake', '0.9.2'
# Use unicorn as the web server
# gem 'unicorn'

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -68,7 +68,7 @@ GEM
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
rake (0.9.2)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
Expand All @@ -85,6 +85,6 @@ DEPENDENCIES
haml
hirb
rails
rake (= 0.8.7)
rake (= 0.9.2)
sqlite3
watchr
3 changes: 2 additions & 1 deletion app/controllers/home_controller.rb
Expand Up @@ -2,13 +2,14 @@ class HomeController < ApplicationController

def index
@post = Post.new

if cookies[:zip_code].present?

begin
@ip_location = get_geo_ip(request.remote_ip)
origin_string = "#{cookies[:zip_code]}, #{@ip_location.country_code if @ip_location.success}"
@posts = Post.within(500, :origin => origin_string).order('distance asc')
@post.country = @ip_location.country_code # use ip address to guess country code

rescue
@posts = Post.all
flash[:error]= "Whoops! We had a problem locating you! Maybe try again?"
Expand Down
2 changes: 2 additions & 0 deletions app/views/home/index.haml
Expand Up @@ -18,6 +18,8 @@
%br/
Near zip code / postal code:
=f.text_field(:zip_code)
Country code:
=f.text_field(:country,{size:3})

%br/
Interested traders email me at:
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20110707210611_add_country_to_post.rb
@@ -0,0 +1,8 @@
class AddCountryToPost < ActiveRecord::Migration
def self.up
add_column :posts, :country, :string
end

def self.down
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110702204607) do
ActiveRecord::Schema.define(:version => 20110707210611) do

create_table "locations", :force => true do |t|
t.datetime "created_at"
Expand All @@ -26,9 +26,9 @@
t.text "zip_code", :limit => 255
t.datetime "created_at"
t.datetime "updated_at"
t.string "note"
t.string "token"
t.datetime "token_timestamp"
t.string "country"
end

add_index "posts", ["lat"], :name => "index_posts_on_lat"
Expand Down

0 comments on commit 4660d04

Please sign in to comment.