Ruby on rails 如何用&;替换HTML标记;书信电报;或;燃气轮机;
查看Ruby on rails 如何用&;替换HTML标记;书信电报;或;燃气轮机;,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,查看 <%= auto_link(simple_format(strip_tags(@string))) %> “条带标签”删除 如何用或替换它们 有什么功能可以做吗? 我的意思是我想逃离@string试试这个: 在app/helpers/application\u helper.rb中添加以下内容 module ApplicationHelper include ActionView::Helpers::OutputSafetyHelper def raw_stri
<%= auto_link(simple_format(strip_tags(@string))) %>
“条带标签”删除
如何用
或
替换它们
有什么功能可以做吗?
我的意思是我想逃离@string试试这个:在app/helpers/application\u helper.rb中添加以下内容
module ApplicationHelper
include ActionView::Helpers::OutputSafetyHelper
def raw_strip(text)
raw(text).gsub('<', '<').gsub('>', '>')
end
end
模块应用程序助手
包括ActionView::Helpers::OutputSafetyHelper
def原始条带(文本)
原始(文本).gsub(“”,“”)
结束
结束
然后,在视图中使用raw\u strip(@string)
。试试这个:在app/helpers/application\u helper.rb中添加以下内容
module ApplicationHelper
include ActionView::Helpers::OutputSafetyHelper
def raw_strip(text)
raw(text).gsub('<', '<').gsub('>', '>')
end
end
模块应用程序助手
包括ActionView::Helpers::OutputSafetyHelper
def原始条带(文本)
原始(文本).gsub(“”,“”)
结束
结束
然后,在视图中使用
raw_strip(@string)
。使用h
辅助功能:
<%= auto_link(simple_format(h(@string))) %>
使用
h
辅助功能:
<%= auto_link(simple_format(h(@string))) %>
只需使用h()方法,如下例所示:
puts h("is a > 0 & a < 10?")
注意:如果您在控制台上执行此操作,则必须执行一些额外的步骤:
require "erb"
include ERB::Util
只需使用h()方法,如下例所示:
puts h("is a > 0 & a < 10?")
注意:如果您在控制台上执行此操作,则必须执行一些额外的步骤:
require "erb"
include ERB::Util
谢谢你的回答。我是否需要包括ActionView::Helpers::OutputSafetyHelper?????我认为不一定。辅助对象已包含在包含该模块的视图中;因此,如果没有这一点,它也必须起作用。为故障保护添加了这个。谢谢你的回答。我是否需要包括ActionView::Helpers::OutputSafetyHelper?????我认为不一定。辅助对象已包含在包含该模块的视图中;因此,如果没有这一点,它也必须起作用。这是为故障保护添加的。这是为好奇者准备的。这是为好奇者准备的。