I have lines of HTML I want to place throughout the Rails view, but I only want the line of code to originate from a single source and not be copied throughout.
Example:
I have the following code I want to put in multiple places:
<i class="bi-trophy-fill" style="font-size: 1.25rem; color: gold;"> 1st Place</i>
So I tried creating a helper method that stores the html as a string:
def place_symbol(place)
if place == 1
string = %(<i class="bi-trophy-fill" style="font-size: 1.25rem; color: gold;"> 1st Place</i>)
elsif place == 2
string = %(<i class="bi-trophy-fill" style="font-size: 1.0rem; color: silver;"> 2nd Place</i>)
elsif place == 3
string = %(<i class="bi-trophy-fill" style="font-size: 1.0rem; color: #CD7f32;"> 3rd Place</i>)
end
return string
end
and in my view I have:
<%= "#{place_symbol(1)}" %>
But it just prints out the string into the view rather than recognizing it as HTML. Is there a rails method where it would know its meant to be html code and not actually printed out?