Sha256: 1751c13b6f67085788d9fef1be92a50ef2e6ceda76321c0e41a4b834276c0764
Contents?: true
Size: 1.02 KB
Versions: 54
Compression:
Stored size: 1.02 KB
Contents
# Each {Article} must have one or more {Author}s. # # An {Author} is unrelated to the currently logged in user. This allows to publish # {Article}s by guest authors that don't need an own user account module Lines class Author < ActiveRecord::Base # Relations has_many :authorables has_many :articles, through: :authorables # Validations validates :name, :email, :description, presence: true # Callbacks before_destroy :check_for_articles # Returns the first name def first_name self.name.split(" ").first end # Returns the last name def last_name self.name.split(" ").last end private # Return false if an author has associated articles. # This check is called before destroying an author to prevent leaving articles # without an associated author. def check_for_articles if articles.count > 0 errors[:base] << "cannot delete author with existing blog articles" return false end end end end
Version data entries
54 entries across 54 versions & 1 rubygems