Reputation: 21
<% @ticket.conversations.each do |c| %>
<section class="messages">
<%="<li> #{c.the_message} </li>" %>
</section>
<%end%>
I am trying to have rails write the HTML code for me so the output would look something like this:
<li>MESSAGE1</li>
<li>MESSAGE2</li>
<li>Next message here...</li>
I am going to style every nth element to have a different style to show what speaker it belongs to. But currently is just outputs straight text and escapes the HTML. How do I stop this escape?
Upvotes: 0
Views: 1512
Reputation: 38645
To output you need to use <%=
as follows within your <section>
block:
<%= "<li> #{c.the_message} </li>".html_safe %>
But currently is just outputs straight text and escapes the HTML
You can use the html_safe
method. Please refer to the "Extensions to String" topic in this document: http://guides.rubyonrails.org/active_support_core_extensions.html
Another option you can use is the raw
helper(as pointed out by Stefan) which calls the html_safe
for you. e.g.
<%= raw "<li> #{c.the_message} </li>" %>
Upvotes: 2
Reputation: 114138
Try it this way:
<% @ticket.conversations.each do |c| %>
<section class="messages">
<li><%= c.the_message %></li>
</section>
<% end %>
Or if you don't want to repeat <section>
every time:
<section class="messages">
<% @ticket.conversations.each do |c| %>
<li><%= c.the_message %></li>
<% end %>
</section>
Upvotes: 0
Reputation: 58224
You can also style your list items this way:
<li><%= c.the_message %></li>
Just based upon preference.
Upvotes: 0