Orsay Orsay - 1 month ago 8
Ruby Question

How to write inline Ruby slim

I would like to have this H2 result in my view :

Lot 1


My views is write in slim and I use locales variables for
Lot

How can I manage to put this both element (
Lot
and index) on the same line.

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


For the moment I have a synthax error.

Answer

Try

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

If think the issue is that you are making a concat between a string and a number

Wait, probably the best solution is interpolation because you need even a space

h2 = "#{t('product.lot')} #{index + 1}"
Comments