On 12/29/05, Mark Daoust
<mark-39zfgdxpqyoVl9nbPrNzI9BPR1lH4CV8@public.gmane.org>
wrote:> I''m sure a real newbie question, but try searching for
''h'' in any search
> engine and you don''t get far.
>
> I am wondering what the h does in Ruby as in the code below:
>
> <%= h(truncate(product.description, 80)) %>
>
h() is shorthand for ''html_escape'', which makes sure the
content is
safe for display on an HTML page.
For example, if your controller had some code in it like:
@example = "<br /><br /><br />"
<%= @example %> in a view would put three breaks in a row, when what
you probably wanted was to display the actual text.
<%= h(@example) %> converts those brackets into HTML entities that
will show up properly.
In general, it''s a good idea to use it whenever you don''t have
total
control over the content, because it will prevent your pages from
melting.