2023-10-05 15:46:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BlogPost < ApplicationRecord
|
|
|
|
belongs_to :user
|
|
|
|
has_rich_text :content
|
|
|
|
|
|
|
|
validates :title,
|
|
|
|
:user,
|
|
|
|
:slug,
|
|
|
|
:content,
|
2023-10-06 07:26:16 +00:00
|
|
|
:summary,
|
2023-10-05 15:46:07 +00:00
|
|
|
presence: true
|
|
|
|
|
2023-10-12 15:24:33 +00:00
|
|
|
validates :published, inclusion: { in: [true, false] }
|
|
|
|
|
2023-10-05 15:46:07 +00:00
|
|
|
validates :slug, uniqueness: true
|
|
|
|
|
2023-10-12 15:24:33 +00:00
|
|
|
scope :published, -> { where(published: true) }
|
|
|
|
scope :draft, -> { where(published: false) }
|
|
|
|
|
2023-10-13 19:28:35 +00:00
|
|
|
paginates_per 15
|
|
|
|
|
2023-10-05 15:46:07 +00:00
|
|
|
def to_param
|
|
|
|
slug
|
|
|
|
end
|
|
|
|
end
|