-
Notifications
You must be signed in to change notification settings - Fork 184
Errors API
Fran Worley edited this page Feb 1, 2017
·
10 revisions
Also remember that dry's error message API is:
messages
(return both errors and hints)
errors
(return just errors)
hints
(return just hints)
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"]
}
}
{
name: ["must be filled"],
nested: {
another: ["must be filled"]
}
}
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"]
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
}
They added a new method to their API for a symbolised description:
model.errors.details
=> {:email=>[{:error=>:blank}]}