friend API development
This commit is contained in:
parent
5ba13fa893
commit
cccae35a97
|
|
@ -0,0 +1,10 @@
|
|||
module JamRuby
|
||||
class FriendRequest < ActiveRecord::Base
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :friend, :class_name => "JamRuby::User"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@ module JamRuby
|
|||
class User < ActiveRecord::Base
|
||||
|
||||
attr_accessible :name, :email, :password, :password_confirmation
|
||||
attr_accessor :updating_password
|
||||
attr_accessor :updating_password, :online
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
|
|
@ -11,6 +11,8 @@ module JamRuby
|
|||
|
||||
has_many :connections, :class_name => "JamRuby::Connection"
|
||||
|
||||
has_many :friend_requests, :class_name => "JamRuby::FriendRequest"
|
||||
|
||||
has_many :friendships
|
||||
has_many :friends, :through => :friendships
|
||||
has_many :inverse_friendships, :class_name => "JamRuby::Friendship", :foreign_key => "friend_id"
|
||||
|
|
@ -35,6 +37,11 @@ module JamRuby
|
|||
#validates :password_confirmation, presence: true
|
||||
validates_confirmation_of :password, :if => :should_validate_password?
|
||||
|
||||
def online
|
||||
@online = !self.connections.nil? && self.connections.size > 0
|
||||
return @online
|
||||
end
|
||||
|
||||
def should_validate_password?
|
||||
updating_password || new_record?
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue