What is the h for?


#1

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


#2

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


#3

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:


#4

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/


#5

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/


#6

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.