Class: AuthorValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/winewoo_core/models/author_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/winewoo_core/models/author_validator.rb', line 3

def validate_each(record, attribute, value)
  if record.vintage
    if record.vintage.user_comments.find_by(winewoo_user_id: value)
      record.errors[:user] = 'has already posted a comment.'
      return false
    end
  end
  return true
end