导轨4具有很小的误差

时间:2014-04-21 20:54:52

标签: ruby-on-rails-4 slim-lang

我有这个简单的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... ... ^

有人知道我在这里做错了吗?

2 个答案:

答案 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