Skip to content
Fran Worley edited this page Feb 1, 2017 · 10 revisions

Dry Validation

Also remember that dry's error message API is:

messages (return both errors and hints) errors (return just errors) hints (return just hints)

Full Messages

Remember that when validating a nested form via reform Dry doesn't know that it's nested and won't return a the complete attribute name.

{ 
  name:   ["name must be filled", "must be string"],
  nested: { 
    another: ["another must be filled"] 
  } 
}

Messages

{ 
  name:   ["must be filled"],
  nested: { 
    another: ["must be filled"] 
  } 
}

AMV

Full Messages

This simply returns a unique array of messages. They simply gsub the dots and capitalise each word of the symbol.

["Name can't be blank", "Nested Another can't be blank"]

Messages

Single level hash with nested models identified via dotted symbols. For collections the dotted symbol doesn't include the items index and the messages unique (i.e. you might have the same error on multiple collection objects but you'll only have one message showing in the main form)

{ 
  name:   ["can't be blank"],
  nested.another: ["can't be blank"], # nested model
  nested.many: ["can't be blank"]  # nested collection
}

Rails 5 AM errors API

They added a new method to their API for a symbolised description:

model.errors.details
=> {:email=>[{:error=>:blank}]}