Hey!
Need help with adding messages to rules for nested params.
I’m getting this error Dry::Validation::MissingMessageError: Message template for :invalid under "data.attributes.phone_number.phone_number_prefix" was not found for such schema:
params do
required(:data).hash do
required(:type).filled(:string)
required(:attributes).hash do
....
required(:phone_number).maybe(:string)
required(:phone_number_prefix).maybe(:string)
end
end
.....
end
rule(data: {attributes: [:phone_number, :phone_number_prefix]}) do
phone_number = ....
key.failure(:invalid) unless phone_number.valid?
end
I tried different nesting of keys in en.yml, but nothing works. This is the last edit:
en:
dry_validation:
errors:
rules:
data:
attributes:
phone_number:
invalid_format: "is of invalid format"
...here go other standard dry-schema errors...
The main problem was that I thought that I NEED to nest parameters in rule “name”, but actually I can put anything I need there in any structure so that my error messages have specific paths afterwards. And we can get values anyway in the rule, so all needed parameters are available in the rule block.
The main problem was that I thought that I NEED to nest parameters in rule “name”
@aleksandra-tomilina so, given the error you got it’s no surprise this is what you thought I think this is a bug, in a way. The error message shouldn’t say data.attributes.phone_number.phone_number_prefix, so it’s worth addressing because I know people may waste a lot of time trying to get stuff working.
Could you please report this and link to this thread?
Yes, sure. The example of yml, file I provided was one of the theories I tried, but yes, the error message definitely added things I should try to debug list
Will report this issue)