如何编写内联Ruby slim

时间:2016-10-28 13:46:39

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

我想在我的观点中得到这个H2结果:

Lot 1

我的观点写得很苗条,我使用Lot的语言环境变量 如何设置将这两个元素(Lot和索引)放在同一行上。

 - @products.each_with_index do |product, index|
        h1 = product.title
        h2 = t('product.lot') + (index + 1) 

目前我有一个synthax错误。

1 个答案:

答案 0 :(得分:0)

尝试

h2 = t('product.lot') + (index + 1).to_s 

如果认为问题是你在字符串和数字之间进行连接

等等,可能最好的解决方案是插值,因为你甚至需要一个空格

h2 = "#{t('product.lot')} #{index + 1}"
相关问题