Class: BelongsToProjectValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/central/support/validators/belongs_to_project_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Checks that the parameter being validated represents a User#id that is a member of the object.project



4
5
6
7
8
9
10
# File 'lib/central/support/validators/belongs_to_project_validator.rb', line 4

def validate_each(record, attribute, value)
  if record.project && !value.nil?
    unless record.project.user_ids.include?(value)
      record.errors[attribute] << "user is not a member of this project"
    end
  end
end