1

I am trying to use the html_safe? method to check if a string/text which is retrieved from the DB contains any HTML. However, the html_safe? method is not returning the value I expected. Let's look at the following examples:

>> 'this is a string'.html_safe?
false

>> '<strong>this is a string</strong>'.html_safe?
false

I would expect the first invocation of html_safe? to return true, and the second invocation to return false. The results on the Rails console return false on both of the invocations...

Am I misunderstanding the purpose of html_safe? or there is a better way of doing what I want to achieve?

Phrancis
  • 2,222
  • 2
  • 27
  • 40
Eric Pau
  • 31
  • 2

1 Answers1

1

After more digging, the html_safe? method only return a boolean value that to indicate whether or not the type/object itself is html safe.

Therefore, it doesn't really matter what the contents are within a string, the html_safe? method would also return false for String type.

Eric Pau
  • 31
  • 2