我有一个富文本字段,它以HTML格式发送数据。我想将它存储在数据库中,但前提是它将实际呈现为某种东西。
例子:

"hello world" => true
"<br><b></b>" => false
"<br><b>How are you today?</b>" => true

最佳答案

检查ActionView::Base.full_sanitizer.sanitize的输出是否为空:

ActionView::Base.full_sanitizer.sanitize("<b>").blank?
# => true
ActionView::Base.full_sanitizer.sanitize("<b> </b>").blank?
#=> true
ActionView::Base.full_sanitizer.sanitize("<b>a</b>").blank?
#=> false

https://stackoverflow.com/a/31180237/580346

08-17 19:37