Sha256: efdcf5116365d5b26f9cc5308b05ef9077efd41d2e0fa3b80584110400b513dc

Contents?: true

Size: 701 Bytes

Versions: 5

Compression:

Stored size: 701 Bytes

Contents

# frozen_string_literal: true

class Author < ApplicationRecord
  has_many :posts
  has_many :published_posts, -> { published }, class_name: 'Post'
  has_many :recent_posts, -> { recents }, class_name: 'Post'

  has_many :tags, through: :posts

  has_one :profile, inverse_of: :author, dependent: :destroy

  has_one_attached :avatar

  accepts_nested_attributes_for :profile, allow_destroy: true
  accepts_nested_attributes_for :posts, allow_destroy: true

  validates :email, format: { with: /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\z/i, message: 'Invalid email' }

  validate -> {
    errors.add( :base, 'Invalid age' ) if !age || age.to_i % 3 == 1
  }

  def to_s
    "#{name} (#{age})"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activeadmin_blaze_theme-0.7.4 spec/dummy/app/models/author.rb
activeadmin_blaze_theme-0.7.0 spec/dummy/app/models/author.rb
activeadmin_blaze_theme-0.6.2 spec/dummy/app/models/author.rb
activeadmin_blaze_theme-0.6.0 spec/dummy/app/models/author.rb
activeadmin_blaze_theme-0.5.16 spec/dummy/app/models/author.rb