Insert ruby in html class=“ ” property

2020-07-30 03:14发布

问题:

This is probably really stupid but I've spent the last 2 hours trying to figure out how to do this with no luck at all.

Basically I need my html page to do the following:

<div class="circleElement">
...
</div>

But I need to add more classes to that div class with ruby, the classes are coming in from a text field in my database.

I tried inserting ruby like:

<div class="circleElement"+ <%= u.tag %> >...</div>

And many different variations of this line with no luck at all :(

I should add that u.tag holds exactly this string> "activeTag classicTag".... so it should append with no problems but it's not doing it!

回答1:

<div class="circleElement <%= u.tag %>" >...</div>

should work.