Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# models/company/note.rb
class Company::Note < ApplicationRecord::Note
alias_attribute :company_id, :article_id
alias_attribute :company, :article
# VALIDATIONS
COMPANY_NOTE_CATEGORIES = %w(
History Organisation Products Technology Significance
)
validates :category, inclusion: { in: COMPANY_NOTE_CATEGORIES }
end
# models/game/note.rb
class Game::Note < ApplicationRecord::Note
alias_attribute :game_id, :article_id
alias_attribute :game, :article
# VALIDATIONS
GAME_NOTE_CATEGORIES = %w(
Development Publishing Technology Sound Reception
)
validates :category, inclusion: { in: GAME_NOTE_CATEGORIES }
end
class Note < ApplicationRecord
# AUDIT
audited on: [:update, :destroy]
# RELATIONSHIPS
belongs_to :article
belongs_to :created_by, class_name: 'User'
# VALIDATIONS
VALID_NOTE_TYPES = %w(Game::Note Company::Note Person::Note)
validates :type, presence: true, inclusion: { in: VALID_NOTE_TYPES }
validates :category, presence: true
validates :body, presence: true, length: { minimum: 5, maximum: 2000 }
validates :cite_url, length: { minimum: 5, maximum: 250 }, allow_blank: true
validates :cite_title, length: { maximum: 250 }, allow_blank: true
validates :cite_website, length: { maximum: 100 }, allow_blank: true
end
# models/person/note.rb
class Person::Note < ApplicationRecord::Note
alias_attribute :person_id, :article_id
alias_attribute :person, :article
# VALIDATIONS
PERSON_NOTE_CATEGORIES = %w(
Personal Education Career Family Achievements
)
validates :category, inclusion: { in: PERSON_NOTE_CATEGORIES }
end
Game::Note.new
(irb):3: warning: toplevel constant Note referenced by Game::Note
=> #<Note id: nil, article_id: nil, type: nil, category: nil, body: nil, cite_url: nil, cite_title: nil, cite_website: nil, created_by_id: nil, created_at: nil, updated_at: nil>
# ^^ This is a new Note class object, not a Game::Note class object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.