【问题标题】:Rails 4 fomatting with slim errorRails 4 格式化错误
【发布时间】:2014-04-21 20:54:51
【问题描述】:

我有这个完美运行的简单 erb 代码,与我的 i18n.yml 文件相连。这个想法是获取客户端的edit.html.erb 页面,在我的en.yml 文件中获取该页面的标题并将该标题传递给@client.fullname 变量。像这样:

<h1><%= t('client.edit.title'), :current_client => @client.fullname %></h1>

现在,我正在将我的 erb 文件转换为 slim。所以那行代码的结果是

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... ... ^

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

【问题讨论】:

  • 我可以使它相对工作的唯一方法是传递带有翻译标识符字符串的 :current_client 选项: = t('client.edit.title', :current_client => @client.fullname)
  • 谢谢,你也明白了!

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


【解决方案1】:

哈希参数选项应该在方法调用括号内传递,像这样

h1 = t('client.edit.title', :current_client => @client.fullname)

不知道为什么这会在 ERB 中起作用,但它看起来不像写的那样正确。

你也可以完全去掉括号

h1 = t 'client.edit.title', :current_client => @client.fullname

【讨论】:

    【解决方案2】:

    请尝试:

    h1
      = t('client.edit.title'), :current_client => @client.fullname
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      相关资源
      最近更新 更多