Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails i18n specific error validation formats

So you can change an error message in en.yml with something like the following:

en:
  activerecord:
    errors:
      models:
        foo:
          attributes:
            amount:
              greater_than_or_equal_to: "Custom GTOE error message."

However, this will say the following:

Amount Custom GTOE error message.

I know I can remove it globally with:

en:
  activerecord:
    errors:
      format: "%{message}"

But can I remvoe the %{attribute} for only this validation?

Thanks!

like image 358
andrewpthorp Avatar asked Oct 01 '12 14:10

andrewpthorp


1 Answers

I'm not sure if you can remove it from the en.yml, but you could make a custom one that I think would have the signature you want:

def discount_cannot_be_greater_than_total_value
    if attribute > total_value
      errors.add(:base, "can't be greater than total value")
    end
end
like image 64
sevensidedmarble Avatar answered Nov 11 '22 22:11

sevensidedmarble