Этот коммит содержится в:
Mattia Roccoberton
2020-09-01 11:12:40 +02:00
родитель 5c462f5d7c
Коммит 7a148c7cd1
82 изменённых файлов: 1707 добавлений и 4 удалений

25
spec/dummy/app/models/post.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,25 @@
# frozen_string_literal: true
class Post < ApplicationRecord
enum state: %i[available unavailable arriving]
belongs_to :author, inverse_of: :posts, autosave: true
has_one :author_profile, through: :author, source: :profile
has_many :post_tags, inverse_of: :post, dependent: :destroy
has_many :tags, through: :post_tags
validates :title, allow_blank: false, presence: true
scope :published, -> { where(published: true) }
scope :recents, -> { where('created_at > ?', Date.today - 8.month) }
def short_title
title.truncate 10
end
def upper_title
title.upcase
end
end