Created
March 26, 2020 15:36
-
-
Save kemenaran/89beb48550b6e2845d57c16fc823fed6 to your computer and use it in GitHub Desktop.
Format error messages for champs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates_associated :champs, :champs_private | |
# -> Rails displays: "Champs is invalid" | |
validates_associated :champs, :champs_private, message: -> (object, _data) { | |
(object.champs + object.champs_private) | |
.reject(&:valid?) | |
.flat_map do |champ| | |
champ.errors.full_messages.map do |message| | |
"#{champ.libelle} : #{message}" | |
end | |
end | |
.to_sentence | |
} | |
# -> Rails displays: "Champs Carte d'identité : Le fichier n’est pas d’un type accepté" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment