Table name: profile_visits
id :integer not null, primary key by_user_id :integer count :integer default(0) created_at :datetime updated_at :datetime for_user_id :integer university_id :integer
To increment profile visit count
# File app/models/profile_visit.rb, line 23 def self.increment!(for_user, by_user = nil) return false if for_user == by_user profile_visit = find_or_initialize_by(for_user_id: for_user.id, by_user_id: by_user.try(:id)) unless profile_visit.by_user_id and profile_visit.visited_today? profile_visit.count += 1 profile_visit.save end end
It returns profile visit count for user.
# File app/models/profile_visit.rb, line 33 def self.visits_count_for(user, by = nil) visits = user.profile_visits visits = visits.where(by_user_id: by.id) visits.sum(:count) end
Create profile visit notification.
# File app/models/profile_visit.rb, line 45 def profile_notification self.create_activity key: 'profile_visit.create', owner: by_user, recipient: for_user, type: 'Notification' end
Checks if profile visited today.
# File app/models/profile_visit.rb, line 40 def visited_today? updated_at and updated_at.in_time_zone.to_date == Date.today_in_time_zone end