Built-in Methods to Encode/Decode HTML?

Are there any built-in methods in either Ruby or Rails to do what this
library does (i.e. encode/decode HTML)?
http://htmlentities.rubyforge.org/

The above library works beautifully but I just expected this sort of
functionality to be part of Ruby/Rails since languages such as PHP,
Java, etc. have this as part of their core functionality.

Thanks.

You can do it with URI

name = “Ruby P.ming Language”
url = “http://example.com/?name=” + URI.escape(name)
puts url # http://example.com/?name=Ruby%20Programming%20Language

On Aug 24, 1:38 pm, Ben K. [email protected]

Ben K. wrote:

Are there any built-in methods in either Ruby or Rails to do what this
library does (i.e. encode/decode HTML)?
http://htmlentities.rubyforge.org/

The above library works beautifully but I just expected this sort of
functionality to be part of Ruby/Rails since languages such as PHP,
Java, etc. have this as part of their core functionality.

For encoding, rails provides h() which is an alias to html_escape(). For
decoding it’s best to use the HTMLEntities library that you already
found. Though you can use the stock CGI::unescape(), that will only
decode numerical HTML entities but no named ones.


Roderick van Domburg
http://www.nedforce.nl

Thanks, Roderick and Pedro. I think I will stick with HTMLEntities for
now :slight_smile:

Anil

Roderick van Domburg wrote:

Ben K. wrote:

Are there any built-in methods in either Ruby or Rails to do what this
library does (i.e. encode/decode HTML)?
http://htmlentities.rubyforge.org/

The above library works beautifully but I just expected this sort of
functionality to be part of Ruby/Rails since languages such as PHP,
Java, etc. have this as part of their core functionality.

For encoding, rails provides h() which is an alias to html_escape(). For
decoding it’s best to use the HTMLEntities library that you already
found. Though you can use the stock CGI::unescape(), that will only
decode numerical HTML entities but no named ones.


Roderick van Domburg
http://www.nedforce.nl

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs