owned_by_validator.rb 253 B

123456
  1. class OwnedByValidator < ActiveModel::EachValidator
  2. def validate_each(record, attribute, association)
  3. return if association.all? {|s| s[options[:with]] == record[options[:with]] }
  4. record.errors.add(attribute, "must be owned by you")
  5. end
  6. end