My models:
Product has_many
variants has_many
sizes
To sizes I add custom error, like this:
errors.add :base, "My custom error msg"
In the view I see: "Sizes base My custom error msg"
class Size < ActiveRecord::Base
...
validate :custom_error, only: :update
...
def custom_error
errors.add :base, "My custom error msg"
end
end
But how translate this message?
UPDATED I am found solution:
In locale.yml:
attributes:
variants/sizes:
base: ''
Try:
errors.add :base, :custom_error
This should give you translation missing
together with key name and a scope where this translation should be stored.
Update:
Just did it by myself:
translation missing: [locale].activerecord.errors.models.[model_name].attributes.base.custom_error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With