-
-
Save tubbo/ce570c339645e366a9fb3470368bc138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models/company/note.rb | |
class Company < ApplicationRecord | |
class Note < ::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 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models/game/note.rb | |
require_dependency 'note' | |
module Game | |
class Note < ::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 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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