2019-08-24 16:51:25 +02:00
|
|
|
class Post < ApplicationRecord
|
|
|
|
|
belongs_to :board
|
|
|
|
|
belongs_to :user
|
|
|
|
|
belongs_to :post_status, optional: true
|
|
|
|
|
|
|
|
|
|
validates :title, presence: true, length: { in: 4..64 }
|
2019-09-04 21:12:07 +02:00
|
|
|
|
|
|
|
|
paginates_per 15
|
2019-09-05 17:11:07 +02:00
|
|
|
|
2019-09-09 16:50:33 +02:00
|
|
|
class << self
|
|
|
|
|
def find_with_post_status_in(post_statuses)
|
|
|
|
|
where(post_status_id: post_statuses.pluck(:id))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def search_by_name_or_description(s)
|
|
|
|
|
s = s || ''
|
|
|
|
|
s = sanitize_sql_like(s)
|
|
|
|
|
where("posts.title ILIKE ? OR posts.description ILIKE ?", "%#{s}%", "%#{s}%")
|
|
|
|
|
end
|
2019-09-05 17:11:07 +02:00
|
|
|
end
|
2019-08-24 16:51:25 +02:00
|
|
|
end
|