Soc/app/models/blog_post.rb

27 lines
488 B
Ruby

# frozen_string_literal: true
class BlogPost < ApplicationRecord
belongs_to :user
has_rich_text :content
validates :title,
:user,
:slug,
:content,
:summary,
presence: true
validates :published, inclusion: { in: [true, false] }
validates :slug, uniqueness: true
scope :published, -> { where(published: true) }
scope :draft, -> { where(published: false) }
paginates_per 15
def to_param
slug
end
end