Interpolation Ruby on Rails I18n

all!

I have a little check for the my: username field, which should be between 4 and 30 characters. I wrote a validation: :length => { :within => 4..30, :message => I18n.t('activerecord.errors.range')- I wanted to display one error message for all kinds of errors (it doesn't seem too_long or too_short), but the question is - can I pass both the minimum and maximum values ​​in the translation in order to have something like: Username must be between 4 and 30 characters. I currently have: range: "should be between %{count} and %{count} characters"which obviously does not work (did this just for verification).

Is it possible to capture these values ​​from a range?

Thanks everyone for the advice!

+5
source share
1 answer

I18n translate ( -t):

I18n.t('activerecord.errors.range', :min => 4, :max => 30)

% {min} % {max}.

, .

+9

All Articles