从字符串 Ruby on Rails 中去除 html [英] Strip html from string Ruby on Rails
本文介绍了从字符串 Ruby on Rails 中去除 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Ruby on Rails,有没有办法使用 sanitize 或 equal 方法从字符串中去除 html
并仅保留输入标签的 value 属性中的文本?
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?
推荐答案
ActionView::Helpers::SanitizeHelper
中有一个 strip_tags
方法:
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags
为了获取 value 属性中的文本,您可以使用类似 Nokogiri 和 Xpath 表达式的东西来将其从字符串中取出.
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屋!
查看全文