I’m trying to output a custom field name for a validation:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'dry-validation'
end
require 'dry-validation'
class RowValidator < Dry::Validation::Contract
params do
required(:amount).filled(:integer, gt?: 0)
end
def self.messages
super.merge(en: {
dry_validation: {
rules: {
amount: "Amount (column 1)",
},
}
})
end
end
validator = RowValidator.new
p validator.call(amount: 0).errors(full: true).map(&:text)
This is outputting “amount must be greater than 0”, but I’d like it to be “Amount (column 1) must be greater than 0”.
Is there a way to do this without using an external i18n file?