Created
August 1, 2018 16:40
-
-
Save leemcalilly/090e03a2b1cd4ab7dc0f566371f42efb to your computer and use it in GitHub Desktop.
This file contains 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 Quote < ApplicationRecord | |
belongs_to :user | |
belongs_to :speaker, class_name: "Artist" | |
belongs_to :topic, class_name: "Artist" | |
belongs_to :genre | |
delegate :medium, to: :genre, allow_nil: true | |
validates :user_id, presence: true | |
validates :text, presence: true, length: { maximum: 1200 } | |
validates :source, presence: true, length: { maximum: 420 }, | |
url: { no_local: true, message: 'needs to be cited with | |
by linking to a real url. Make sure to use http:// | |
or https://.' } | |
validates :speaker_id, presence: true | |
validates :topic_id, presence: true | |
validate :topic_cant_be_a_speaker | |
validate :text_cannot_have_double_quotes_included | |
private | |
def topic_cant_be_a_speaker | |
errors.add(:topic, 'can\'t be the same as the speaker. We don\'t allow | |
artists to talk about themselves ;)') if speaker == topic | |
end | |
def text_cannot_have_double_quotes_included | |
if text.scan('"').present? | |
errors.add(:text, 'for your quote doesn\'t require you to add the | |
"double quotes." We\'ll add those for you."') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment