我有这个简单的erb代码,与我的i18n.yml
文件联合起来。我们的想法是获取客户端的edit.html.erb
页面,在我的en.yml
文件中获取该页面的标题,并将该标题传递给@client.fullname
变量。像这样:
<h1><%= t('client.edit.title'), :current_client => @client.fullname %></h1>
现在,我正在将我的erb文件翻译成苗条。所以这行代码的结果是
h1 = t('client.edit.title'), :current_client => @client.fullname
但它不会将变量传递给en.yml
文件。相反,它会抛出此错误:
/app/views/clients/edit.html.slim:1: syntax error, unexpected ',', expecting ')' ...tty2 = (t('client.edit.title'), :current_client => @client.f... ... ^
有人知道我在这里做错了吗?
答案 0 :(得分:0)
请尝试:
h1
= t('client.edit.title'), :current_client => @client.fullname
答案 1 :(得分:0)
哈希参数选项应该在方法调用括号内传递,如此
h1 = t('client.edit.title', :current_client => @client.fullname)
不确定为什么这会在ERB中起作用,但它看起来并不像写的那样正确。
您也可以完全删除括号
h1 = t 'client.edit.title', :current_client => @client.fullname