简体   繁体   中英

Using ruby variables as html code

I would expect that the following:

<div style="padding-top:90px;"><%= u.one_line %></div>

simply pulls whatever is in u.one_line (which in my case is text from database), and puts it in the html file. The problem I'm having is that sometimes, u.one_line has text with formatted html in it (just line breaks). For example sometimes:

u.one_line is "This is < / b r > awesome"

and I would like the page to process the fact that there's a line break in there... I had to put it with spaces up ^^^ here because the browser would not display it otherwise on stackoverflow. But on my server it's typed correctly, unfortunately instead of the browser processing the line break, it prints out the "< / b r>" part...

I hope you guys understand what I mean :(?

always remember to use raw or html_safe for html output in rails because rails by default auto-escapes html content for protecting against XSS attacks.

for more see When to use raw() and when to use .html_safe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM