Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my embedded ruby string outputting two strings in the html?

I have the following table row with embedded ruby:

<tr class=<%= "image-carousel-show thumb-#{index}" %>>

Which creates this:

<tr class="image-carousel-show" thumb-0="">

However, I want the thumb-0 to be in the class of the row, not as it's own attribute like it currently is.

This is what I want it to show up as:

<tr class="image-carousel-show thumb-0">

I'm not sure why it's doing this, in the ERB I have it all as one string so I don't know why it's being outputted as two.

like image 405
Snubber Avatar asked Aug 14 '26 21:08

Snubber


1 Answers

This is not done by erb but it is modified by the browser, as those params are not placed within quotes. Try:

<tr class="<%= "image-carousel-show thumb-#{index}" %>">

Also there is absolutely no sense of having both classes within erb. This will do the same and is slightly more readable.

<tr class="image-carousel-show thumb-<%= index %>">
like image 135
BroiSatse Avatar answered Aug 16 '26 19:08

BroiSatse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!