Soc/app/models/blog_post.rb

27 lines
488 B
Ruby
Raw Normal View History

# 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,
presence: true
2023-10-12 15:24:33 +00:00
validates :published, inclusion: { in: [true, false] }
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
def to_param
slug
end
end