【发布时间】:2014-12-29 21:39:02
【问题描述】:
我在.each 循环中使用.html_safe 时遇到了问题。这是我可以设置的方法...
class Players < ApplicationController::Base
def index
@players = Players.all
end
end
在视图中:
<% @players.each do |player| %>
<div>
<%= player.stat_code.html_safe %>
</div>
<% end %>
现在stat_code 将是一段很长的 HTML 代码块......(我没有这个案例的示例)但它是 HTML。
在.each 循环中使用.html_safe 似乎没有任何作用。为什么什么都没有发生,您会推荐什么其他解决方案?
注意:我还读到使用.html_safe 很糟糕!对于这种特殊情况,我不在乎。
【问题讨论】:
-
我想我用
sanitize而不是html_safe完成了我的问题....
标签: html ruby-on-rails erb