Frage

When I include '.html_safe', I find that the styling (lass = 'lead' style = 'font-size: 14px;') doesn't get used. When I remove .html_safe, I get the styling but now all the html is shown.

Any advice on how to fix this?

    <p class = 'lead' style = 'font-size: 14px;'>
        <div id = 'textcontainer'>
            <%= @chapter.chaptext.html_safe %>
        </div> <!-- end of textcontainer div -->
    </p>    

Content of @chapter.chaptext without html:

<p> Sanjaya said: <a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'>Lord Krishna</a></a></a></a></a></a></a></a></a> spoke these wor<a href = '#' class = 'getannotation'>ds to Arjuna</a> whose eyes were
<a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'>tearful and downcast</a></a>, and who was ov<a href = '#' class = 'getannotation'>erwh</a>elmed <a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'>with compassion and despair</a></a>.
(2.01) <p>

<p> The Supreme Lord said: How has the dejection come to you at this
juncture? This is n<a href = '#' class = 'getannotation'>ot fit for an Arya</a>n (or the people of noble mind and
deeds). It is disgraceful, and it does not lead one to heaven, O Arjuna.
(2.02)<br>

<p> Do not become a coward, O Arjuna, because it does not befit you. Shake
off this weakness of your heart and get up (for the battle), O Arjuna.
(2.03) <p>
War es hilfreich?

Lösung

It works without .html_safe because @chapter.chaptext is being rendered as a string inside textcontainer. I think the problem is that class = 'getannotation' is overriding your style (lead class) or maybe id = 'textcontainer' with a style rule like #textcontainer p { font-size: 20px;}

Use a web inspector tool to see what style is being applied to chaptext content and where it come from (CSS class).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top