In the "Agile Web Development 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 -- Posted via http://www.ruby-forum.com/.
On Apr 8, 2006, at 14:41, Harro wrote:> In the "Agile Web Development 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.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
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(''<b>Hi There</b>'') => "<b>Hi There</b>" irb(main):004:0> Erik. Harro schreef:> In the "Agile Web Development 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 > >
> It escapes the input for display in HTML.<...>> > In the "Agile Web Development 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/
Rimantas Liubertas wrote:> > And you can read about it in the same book, pages 331-332 if I am not > mistaken. > > > Regards, > RimantasThanks all for the help. I really should hav read on :S. Thanks again, Harro. -- Posted via http://www.ruby-forum.com/.
The actual pages on h() or html_escape() from Agile Web Development are: 344 and 443. Just FYI. -- ro Rimantas Liubertas wrote:>> It escapes the input for display in HTML. > <...> >> > In the "Agile Web Development 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/-- Posted via http://www.ruby-forum.com/.