繁体   English   中英

设计flash消息中的字符串插值?

[英]string interpolation in devise flash messages?

我是RoR的新手,我想个性化Devise flash消息以使用当前用户的名字。

我已经看到原始文件包含以下行:

devise.en.yml

  failure: "Could not authenticate you from %{kind} because \"%{reason}\"."

所以我已经应用了相同的规则:

sessions:
  signed_in: "Welcome back!."
  signed_out: "See you soon!."

-

sessions:
  signed_in: "Welcome back! \"#{current_user.first_name}\"."
  signed_out: "See you soon! \"#{current_user.first_name}\"."

但代码没有执行,并将整个句子打印为字符串。

任何帮助,将不胜感激! :)

它应该是

sessions:
  signed_in: "Welcome back! %{name}."
  signed_out: "See you soon! %{name}."

你必须把它称为:

t('sessions.signed_in', name: current_user.first_name)
t('sessions.signed_out', name: current_user.first_name)

您不能在yml文件中使用ruby插值,但可以将变量传递给translation并使用yml插值语法%{}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM