CristiRazvi / enum_attributes_validation

Enum Attributes Validation provides validation functionality for enum attributes in models.
MIT License
32 stars 7 forks source link

Default English translation missing #11

Open vfonic opened 3 years ago

vfonic commented 3 years ago

I just found this gem. It's exactly what I need! Thank you!

I have several models that have pretty-much the same enum. I'd like to have a single error message for all of these enums.

Is it possible for me to add an entry like this to my config/locales/en.yml:

en:
  activerecord:
    errors:
      models:
        attributes:
          invalid_enum: "can't be %{value}. Valid values are: %{valid_values}"

I tried this and it doesn't work.

CristiRazvi commented 3 years ago

@vfonic sorry for the late response currently it's not possibleto add a general error message for all the models

kirillshamardin commented 1 year ago

@vfonic @CristiRazvi

It works fine:

en:
  errors:
    messages:
      invalid_enum: "can't be %{value}. Valid values are: %{valid_values}"
janospapp commented 1 year ago

I also found that the default option provided to self.errors.add is actually ignored. Recent ActiveModel expects the parameter to be called message instead. I'm not sure if this was always the case, or it was changed in a past version. Or maybe I misunderstood the default parameter, and it's for something else. :thinking: