# What is the h for?

**URL:** <https://www.ruby-forum.com/t/what-is-the-h-for/57242>\
**Category:** Rails\
**Created:** [April 8, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242 "2006-04-08T14:41:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![harro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e79b87/32.png) [@harro](https://www.ruby-forum.com/u/harro)\
**Post date:** [April 8, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242/1 "2006-04-08T14:41:39Z")

</div>

In the “Agile Web D. with Rails” book it runs through making an  
example application, a shopping cart.

In one of the views files, there is one line of code I dont understand  
(below), I dont know what the “h” is for, also I took the h out, and it  
did not affect the application (as far as i could see).

\<%= h(product.title) %\>

Can anyone shed some light on this for me please.

Thanks very much, Harro

---

<div class="post-metadata">

**Author:** ![harro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e79b87/32.png) [@harro](https://www.ruby-forum.com/u/harro)\
**Post date:** [April 8, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242/2 "2006-04-08T14:52:07Z")

</div>

On Apr 8, 2006, at 14:41, Harro wrote:

> Can anyone shed some light on this for me please.

It escapes special HTML characters. If the title is “Bonnie & Clyde”  
you get the valid “Bonnie & Clyde” thanks to h(). You want to use  
h() practically always.

– fxn

---

<div class="post-metadata">

**Author:** ![harro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e79b87/32.png) [@harro](https://www.ruby-forum.com/u/harro)\
**Post date:** [April 8, 2006, 2:55pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242/3 "2006-04-08T14:55:13Z")

</div>

It escapes the input for display in HTML.

irb(main):001:0\> require ‘erb’  
=\> true  
irb(main):002:0\> include ERB::Util  
=\> Object  
irb(main):003:0\> h(‘ **Hi There** ’)  
=\> “\<b\>Hi There\</b\>”  
irb(main):004:0\>

```
 Erik.

```

Harro schreef:

---

<div class="post-metadata">

**Author:** ![harro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e79b87/32.png) [@harro](https://www.ruby-forum.com/u/harro)\
**Post date:** [April 8, 2006, 2:58pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242/4 "2006-04-08T14:58:19Z")

</div>

> It escapes the input for display in HTML.  
> \<…\>
> 
> > In the “Agile Web D. with Rails” book it runs through making an  
> > example application, a shopping cart.  
> > \<…\>

And you can read about it in the same book, pages 331-332 if I am not  
mistaken.

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![harro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e79b87/32.png) [@harro](https://www.ruby-forum.com/u/harro)\
**Post date:** [April 10, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242/5 "2006-04-10T16:16:27Z")

</div>

The actual pages on h() or html\_escape() from Agile Web D. are:  
344 and 443. Just FYI.

–  
ro

Rimantas L. wrote:

> > It escapes the input for display in HTML.  
> > \<…\>
> > 
> > > In the “Agile Web D. with Rails” book it runs through making an  
> > > example application, a shopping cart.  
> > > \<…\>
> 
> And you can read about it in the same book, pages 331-332 if I am not  
> mistaken.
> 
> ## Regards, Rimantas
> 
> [http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![harro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e79b87/32.png) [@harro](https://www.ruby-forum.com/u/harro)\
**Post date:** [April 8, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/what-is-the-h-for/57242/6 "2006-04-08T15:13:23Z")

</div>

Rimantas L. wrote:

> And you can read about it in the same book, pages 331-332 if I am not  
> mistaken.
> 
> Regards,  
> Rimantas

Thanks all for the help. I really should hav read on :S.

Thanks again, Harro.
