我有这两行输出变量。
<%= val %>
<%= v.input_field :value, value: val%>
但同一事物的输出是不同的。
<div>this is <strong style="text-decoration: underline;"> <span>underline</span></strong> now</div>
<div>this is <strong>underline</strong> now</div>
可能是同样的事情解析不同的原因是什么?可能的解决方案?谢谢。
默认情况下,rails会在模板中转义html,如果你想要按原样渲染val
的值 - 使用<%= val.html_safe %>
或<%= raw val %>
,但要注意可能的XSS。