BDubbs
BDubbs

Reputation: 103

Why is HTML stored in a variable not displaying as HTML?

I have created my layout in application.html.erb.

I want to include a few dynamic fields provided from the view. In application.html.erb file I have:

  <p style="margin-left: 45px">
     <%= yield ( :article_heading ) %>
  </p> 

Then in static_page/home.html.erb I have:

<% provide(:article_heading, 'Contact N&ugrave;R&ugrave;mie') %>

The HTML is not being properly parsed. Instead of producing the accent marks, it returns the string exactly.

Upvotes: 0

Views: 48

Answers (1)

user1675011
user1675011

Reputation:

x = "this is some <p>html content</p>"

if in your view you do

  <%= x %> 

then you'll get exactly that string, but this will be interpreted as html code if you do

  <%= x.html_safe %>

Upvotes: 1

Related Questions