Slide 25
Slide 25 text
ありそうなモデル
class Article < ApplicationRecord
belongs_to :publisher, class_name: 'User', optional: true
belongs_to :archiver, class_name: 'User', optional: true
enum status: { draft: 0, published: 1, archived: 2 }
validates :title, presence: true
validates :publisher_id, presence: true, unless: :draft?
validates :archiver_id, presence: true, if: :archived?
def publish_by(user)
update(publisher: user, published_at: Time.current)
end
end
25