Sha256: 41f5f4a13c3222d8e3f191b6cb156020272b86d36c6326bbdf3b80be3f2e1614
Contents?: true
Size: 1.67 KB
Versions: 2
Compression:
Stored size: 1.67 KB
Contents
class Dhatu::BlogPost < Dhatu::ApplicationRecord # Set Table Name self.table_name = "blog_posts" # Including the State Machine Methods include Publishable include Featureable # Validations validates :title, presence: true, length: {minimum: 5, maximum: 256}, allow_blank: false validates :slug, uniqueness: true, presence: true, length: {minimum: 5, maximum: 64}, allow_blank: false validates :author, length: {minimum: 3, maximum: 250}, allow_blank: true validates :description, presence: true validates :posted_at, presence: true validates :meta_description, presence: true, length: {minimum: 10, maximum: 500}, allow_blank: false # Associations has_one :cover_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CoverImage" has_many :gallery_images, :as => :imageable, :dependent => :destroy, :class_name => "Image::GalleryImage" # Serializers serialize :tags, Hash # ------------------ # Class Methods # ------------------ scope :search, lambda { |query| where("LOWER(title) LIKE LOWER('%#{query}%') OR\ LOWER(author) LIKE LOWER('%#{query}%') OR\ LOWER(description) LIKE LOWER('%#{query}%')") } scope :upcoming, lambda { where("starts_at >= ?", Time.now) } scope :past, lambda { where("starts_at < ?", Time.now) } # ------------------ # Instance Methods # ------------------ # Generic Methods # --------------- def display_name "#{title_was}" end # Permission Methods # ------------------ def can_be_edited? status?(:published) or status?(:unpublished) end def can_be_deleted? status?(:removed) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dhatu-0.1.4 | app/models/dhatu/blog_post.rb |
dhatu-0.1.3 | app/models/dhatu/blog_post.rb |