cantino/huginn

View on GitHub
app/validators/owned_by_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
class OwnedByValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, association)
    return if association.all? {|s| s[options[:with]] == record[options[:with]] }
    record.errors.add(attribute, "must be owned by you")
  end
end