如何在常规 Ruby 代码(非 Rails)中使用 strip_tags? [英] How can I use strip_tags in regular Ruby code (non-rails)?

查看:22
本文介绍了如何在常规 Ruby 代码(非 Rails)中使用 strip_tags?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 HTML 转换为纯文本.ActionView 的 SanitizeHelper 中有一个很好的功能,但我无法理解如何引用它并在简单的 test.rb 文件中使用它.

I need to turn HTML into plain text. There's a nice function that does that in ActionView's SanitizeHelper, but I have trouble understanding how I can reference it and use it in a simple test.rb file.

http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html

我希望能够调用 strip_tags("<b>lol</b>") =>哈哈"

推荐答案

这个问题很老了,但我最近也遇到了同样的问题.我找到了一个简单的解决方案:gem sanitize.它很轻,工作正常,并且如果您需要它们还有其他选项.

The question is quite old, but I had the same problem recently. I found a simple solution: gem sanitize. It's light, works fine and has additional options if you need them.

Sanitize.clean("<b>lol</b>") #=> "lol"

这篇关于如何在常规 Ruby 代码(非 Rails)中使用 strip_tags?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆