ruby-on-rails - 将自定义参数传递给 devise.en.yml 以在错误消息中使用
问题描述
如果您在尝试登录应用程序时被锁定,我必须使用 Devise 对 Rails 应用程序进行更新,以显示剩余分钟数。
在 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."
我在 locked: 错误消息中有名为“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,设置了默认语言环境,尝试了一大堆在线推荐,但没有运气。
有任何想法吗?
干杯,阿德里安
解决方案
变量必须作为哈希传递,而不仅仅是一个值。
在您看来,您应该尝试使用以下方式调用翻译:
I18n.t 'devise.failure.locked', number_of_minutes: <value>
替换为您需要的变量
推荐阅读
- java - 在 java 中使用 ArrayList.get() 的 NullPointerException
- python - Python:从链表返回数组中的某些类变量
- python - 无法在 numpy 数组中重新分配值
- ntp - 网络时间协议 V4 - 数据包中的扩展字段计数
- php - 我无法通过 curl 登录网站
- python - 如何在 Windows 中使用 cmd 安装 SQLAlchemy
- javascript - 我无法使用 react 和 javascript 将订购商品的数量保存在本地存储中
- python - 欧拉角引起的机器人定向问题
- docker - 如何在 Dockerfile 中将文件夹的权限更改为 777?
- python - 用for循环转换多列的数据类型