3

I have a rich text field that is sending data in an HTML format. I want to store it in a database, but only if it will actually render as something.

Example:

"hello world" => true
"<br><b></b>" => false
"<br><b>How are you today?</b>" => true
mrzasa
  • 22,895
  • 11
  • 56
  • 94
Stephen
  • 121
  • 7

1 Answers1

6

Check if output of ActionView::Base.full_sanitizer.sanitize is blank:

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

mrzasa
  • 22,895
  • 11
  • 56
  • 94