aj soprano
aj soprano

Reputation: 151

<p> tag not being rendered properly in erb file

I have a list like so

[
    {"name": "ryan", 
    "age": "12", 
    "gender":"male"
    },
    
]

And I have code to render each value in the hash in the list like so:

         <div>
            <% @list.each do |student| %>
                <%= student.each do |k,v|%>
                    <p> <%=v%> </p>
                <% end %>
            <% end %>
        </div>

I would expect each value (ryan, 12 , male) to be wrapped in the <p> tag however, for some reason the first value Ryan does not get wrapped in the tag when looking at the DOM. enter image description here

It can be seen that the <p> tag is empty where Ryan should be. Why is this happening?

Upvotes: 0

Views: 253

Answers (1)

gsumk
gsumk

Reputation: 891

<%= student.each do |k,v|%>

is printing tag, you can use try using a non-printing tag(tag without =)

<% student.each do |k,v|%>

More about ERB tags here

Upvotes: 1

Related Questions