views:

25

answers:

1

Hi,

This might be a simple question to answer, but I couldn't find the answer.

In ruby on rails, I thought the helper function would help escape special characters.

Example: " She's the one that took me "to" "

Code wise: <%= h("She's the one that took me "to" ") %>

However, the double quote won't allow me to display the code on the browser and gives me an error.

I thought the h() is an alias for html_escape() and they convert the following 4 characters

 <   >    &    "

into

&lt;   &gt;  &amp;  &quot;

Is there something i'm missing with using double quotes?

Any advice appreciated Thanks, D

+3  A: 

The problem is that your double quote around the word to is closing the double quote opened at the beginning of the string. Try this:

<%= h("She's the one that took me \"to\" ") %>

Or, to avoid having to backslashify the internal double quotes, you could use the % syntax for creating the string:

<%= h(%[She's the one that took me "to" ]) %>
srparish