Class: Integral::PostViewing

Inherits:
ApplicationRecord show all
Defined in:
app/models/integral/post_viewing.rb

Overview

Represents when a visitor views a post. Keeps track of unique view count based on IP address

Class Method Summary collapse

Methods inherited from ApplicationRecord

available_statuses

Class Method Details

.add(post, ip_address) ⇒ Boolean

Adds a post viewing if it does not already exist

Parameters:

  • post (Post)

    object which has been viewed

  • ip_address (String)

    ip_address of the viewer

Returns:

  • (Boolean)

    whether or not the viewing was successfully added



12
13
14
15
16
17
# File 'app/models/integral/post_viewing.rb', line 12

def self.add(post, ip_address)
  return false if where(post: post, ip_address: ip_address).exists?

  create!(post: post, ip_address: ip_address)
  true
end