Commit 4fb77449

mo khan <mo@mokhan.ca>
2013-07-02 19:04:42
display nearby users on profile page
1 parent 962ad75
Changed files (5)
app/controllers/profiles_controller.rb
@@ -8,6 +8,7 @@ class ProfilesController < ApplicationController
   def show
     @user = User.find(params[:id])
     @creations = @user.creations.includes([:user, :photos]).page(params[:page]).per(18)
+    @nearby_users = @user.nearbys(50) || []
   end
 
   def favorites
app/models/user.rb
@@ -1,6 +1,8 @@
 class User < ActiveRecord::Base
   include PublicActivity::Model
   tracked
+  geocoded_by :last_sign_in_ip, :latitude => :latitude, :longitude => :longitude
+  after_validation :geocode, :if => lambda { |x| x.last_sign_in_ip_changed? }
   validates :name,  :presence => true
   validates :website, :format => URI::regexp(%w(http https)), :allow_blank => true
   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
app/views/profiles/show.html.erb
@@ -19,6 +19,16 @@
         <% end %>
       </div>
     </div>
+    <% if @nearby_users.any? %>
+    <div>
+      <h4>Other Artists Nearby</h4>
+      <ul class="unstyled">
+      <% @nearby_users.each do |item| %>
+        <li><%= link_to item.name, profile_path(item) %> <small>(<%= item.city %>)</small></li>
+      <% end %>
+      </ul>
+    </div>
+    <% end %>
   </div>
   <div class="span9">
     <h1><%= @user.name %> <small>A member since <%= @user.created_at.to_s :foomat %>, with <%= @user.creations.length %> creations.</small> </h1>
Gemfile
@@ -21,6 +21,7 @@ gem 'capistrano-gitflow'
 gem 'dotenv-rails'
 gem 'airbrake'
 gem 'public_activity'
+gem 'geocoder'
 
 group :development, :test do
   gem 'pg'
Gemfile.lock
@@ -150,6 +150,7 @@ GEM
     formatador (0.2.4)
     formtastic (2.2.1)
       actionpack (>= 3.0)
+    geocoder (1.1.8)
     has_scope (0.5.1)
     highline (1.6.15)
     hike (1.2.1)
@@ -324,6 +325,7 @@ DEPENDENCIES
   ffaker
   fog
   formtastic
+  geocoder
   jasmine
   jquery-fileupload-rails
   jquery-rails