Exception: Formify::Errors::ValidationError

Inherits:
FormError
  • Object
show all
Defined in:
lib/formify/errors/validation_error.rb

Instance Attribute Summary collapse

Attributes inherited from FormError

#form

Instance Method Summary collapse

Constructor Details

#initialize(form:) ⇒ ValidationError

Returns a new instance of ValidationError.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/formify/errors/validation_error.rb', line 6

def initialize(form:)
  first_error = form.errors.first
  @attribute = if first_error.methods.include?(:attribute)
                 first_error.attribute
               else
                 first_error.first
               end

  super(
    form: form,
    message: form.errors.full_messages_for(@attribute).first
  )
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



4
5
6
# File 'lib/formify/errors/validation_error.rb', line 4

def attribute
  @attribute
end