Skip to content

Instantly share code, notes, and snippets.

@chap
Created June 10, 2011 21:55
Show Gist options
  • Save chap/1019854 to your computer and use it in GitHub Desktop.
Save chap/1019854 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
def find_matches
User.where(:city => self.city)
# self == the user object you called this function on
end
end
class UsersController < ApplicationController
def match
@user = User.find(params[:id])
@matches = @user.find_matches
# @matches is an array of user objects (look at users#index to see how to iterate over an array of user objects
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment