Передайте пользовательский параметр в devise.en.yml для использования в сообщении об ошибке - PullRequest
0 голосов
/ 27 января 2020

Мне нужно обновить приложение rails, используя Devise, чтобы показать количество оставшихся минут, если вы заблокированы при попытке входа в приложение.

В devise.en.yml У меня есть файл:

en:
  devise:
    confirmations:
      confirmed: "Your email address has been successfully confirmed."
      send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
      send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
    failure:
      already_authenticated: "You are already signed in."
      inactive: "Your account is not activated yet."
      invalid: "Invalid %{authentication_keys} or password."
      locked: "Your account is locked. Please try again in %{number_of_minutes} minutes"
      last_attempt: "You have one more attempt before your account is locked."
      not_found_in_database: "Invalid %{authentication_keys} or password."
      timeout: "Your session expired. Please sign in again to continue."
      unauthenticated: "You need to sign in or sign up before continuing."

В заблокированном сообщении об ошибке есть переменная 'number_of_minutes', но независимо от того, что я пытаюсь получить, я получаю:

missing interpolation argument :number_of_minutes in "Your account is locked. Please try again in %{number_of_minutes} minutes" ({:resource_name=>:user, :authentication_keys=>"E-mail address"} given)

Я добавил его в представление, переопределенный SessionsController, установил локаль по умолчанию, перепробовал целую кучу онлайн-рекомендаций и не повезло.

Есть идеи?

Приветствия, Адриан

1 Ответ

0 голосов
/ 27 января 2020

Переменные должны передаваться как Ха sh, а не просто как значение.

По вашему мнению, вы должны попытаться вызвать перевод с помощью:

I18n.t 'devise.failure.locked', number_of_minutes: <value>

Замена с нужной вам переменной

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...