Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在each循环中使用.html_safe_Html_Ruby On Rails_Erb - Fatal编程技术网

在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
解决了我的问题。。。。