在each循环中使用.html_safe
我在在each循环中使用.html_safe,html,ruby-on-rails,erb,Html,Ruby On Rails,Erb,我在中使用.html\u safe时遇到问题。每个循环。这是我如何设置的 class Players < ApplicationController::Base def index @players = Players.all end end class播放器
中使用.html\u safe
时遇到问题。每个循环。这是我如何设置的
class Players < ApplicationController::Base
def index
@players = Players.all
end
end
class播放器
他认为:
<% @players.each do |player| %>
<div>
<%= player.stat_code.html_safe %>
</div>
<% end %>
现在,stat\u code
将是一个很长的HTML代码块。。。(我没有这个例子)但它是HTML
使用.html\u safe
似乎在循环中没有任何作用。为什么什么都没有发生?您会推荐什么其他解决方案
注意:我还读到使用.html\u safe
是不好的!对于这件事我不在乎 我通过使用sanitize
而不是.html\u safe
设置视图来完成我的问题,就像这样
<% @players.each do |player| %>
<div>
<%= sanitize player.stat_code %>
</div>
<% end %>
我想我是用sanitize
而不是html\u-safe
解决了我的问题。。。。