add search by terms on posts

This commit is contained in:
João Victor Geonizeli
2022-02-28 13:45:28 -03:00
parent aa0e1ac1c7
commit a08a889e7d
5 changed files with 16 additions and 8 deletions

View File

@@ -1,15 +1,15 @@
class Post < ApplicationRecord
include PgSearch::Model
belongs_to :user
belongs_to :quoted_post, optional: true, class_name: 'Post'
validates :content, length: { maximum: 777 }
validates :content, presence: true, unless: :repost?
validate :user, :limit_of_post_per_day
scope :by_user_follows, ->(user) {
where(user_id: user.following_ids)
}
pg_search_scope :by_terms, against: :content
scope :by_user_follows, ->(user) { where(user_id: user.following_ids) }
def repost?
kind == :quoted_post