Forum: Ruby on Rails Method to remove html escape characters from strings

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1a6c6f6af9928f1851b5fd63849b1d23?d=identicon&s=25 Karl (Guest)
on 2009-04-08 20:43
(Received via mailing list)
Is there a convenient way of removing html escape characters from
Strings? I could do using reg exp as in:

=> "hello & goodbye"
>> "hello & goodbye".gsub(/&/, "&")
=> "hello & goodbye"

but I figured there might be a better way.

thx.
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-08 21:05
(Received via mailing list)
> Is there a convenient way of removing html escape characters from
> Strings? I could do using reg exp as in:
>
> => "hello & goodbye"
>>> "hello & goodbye".gsub(/&/, "&")
> => "hello & goodbye"
>
> but I figured there might be a better way.

require 'CGI'>> require 'CGI'
=> true
 >> CGI::unescapeHTML("hello & goodbye "bar" <baz>")
=> "hello & goodbye "bar" <baz>"
1a6c6f6af9928f1851b5fd63849b1d23?d=identicon&s=25 Karl Baum (Guest)
on 2009-04-08 22:37
(Received via mailing list)
That worked.  Thanks!
4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2009-04-08 22:58
(Received via mailing list)
If found this little snap that I got in my application_helper

  def remove_html_tags(str)
    str.gsub(/<\/?[^>]*>/, "")
  end
This topic is locked and can not be replied to.