Class: ScopeBelongsToComponentValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/scope_belongs_to_component_validator.rb

Overview

This validator ensures the scope is a scope of a component scope

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
# File 'app/validators/scope_belongs_to_component_validator.rb', line 5

def validate_each(record, attribute, value)
  return unless component_for(record)

  record.errors.add(attribute, :invalid) if component_for(record).out_of_scope?(Decidim::Scope.find_by(id: value))
end