harro
April 8, 2006, 2:41pm
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
harro
April 8, 2006, 2:52pm
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
harro
April 8, 2006, 2:55pm
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:
harro
April 8, 2006, 2:58pm
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/
harro
April 10, 2006, 4:16pm
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/
harro
April 8, 2006, 3:13pm
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.