从字符串Ruby on Rails中去除html [英] Strip html from string Ruby on Rails

查看:158
本文介绍了从字符串Ruby on Rails中去除html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby on Rails,是否有一种方法可以使用sanitize或equal方法从字符串中去除 html ,并且只在输入标记中保留value属性值属性?

解决方案中有一个 strip_tags ActionView :: Helpers :: SanitizeHelper



http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags



编辑:为了获取value属性中的文本,可以使用Nokogiri和Xpath表达式来将其从字符串中取出。


I'm working with Ruby on Rails, Is there a way to strip html from a string using sanitize or equal method and keep only text inside value attribute on input tag?

解决方案

There's a strip_tags method in ActionView::Helpers::SanitizeHelper:

http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags

Edit: for getting the text inside the value attribute, you could use something like Nokogiri with an Xpath expression to get that out of the string.

这篇关于从字符串Ruby on Rails中去除html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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