daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 61 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. class User < ActiveRecord::Base
  2.     has_many :tags
  3.     has_many :products
  4.     has_many :friendships
  5.    
  6.     validates_presence_of :fuid
  7.     validates_uniqueness_of :fuid
  8.    
  9.     def self.import(facebook_session)
  10.         user = self.create!(:fuid => facebook_session.user.uid)
  11.         facebook_session.user.friends.each do |friend|
  12.              self.add_friend(user.id, friend.uid)
  13.         end
  14.         user
  15.     end
  16.    
  17.     def self.add_friend(user_id, friend_fuid)
  18.         friend = self.find_by_fuid(friend_fuid)
  19.         if friend
  20.             Friendship.create!(:user_id => user_id, :friend_id => friend.id)
  21.             Friendship.create!(:user_id => friend.id, :friend_id => user_id)
  22.         end
  23.     end
  24.    
  25.     def friends
  26.         friendships.each do |friendship|
  27.             user = User.find_by_user_id(friendship.friend_id)
  28.             users << user
  29.         end
  30.         users
  31.     end
  32. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top