escaping - Escape characters <%= h("") %> and how to deal with double quote in Ruby on Rails -


this might simple question answer, couldn't find answer.

in ruby on rails, thought helper function escape special characters.

example: " she's 1 took me "to" "

code wise: <%= h("she's 1 took me "to" ") %>

however, double quote won't allow me display code on browser , gives me error.

i thought h() alias html_escape() , convert following 4 characters

 <   >    &    " 

into

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

is there i'm missing using double quotes?

any advice appreciated thanks, d

the problem double quote around word to closing double quote opened @ beginning of string. try this:

<%= h("she's 1 took me \"to\" ") %> 

or, avoid having backslashify internal double quotes, use % syntax creating string:

<%= h(%[she's 1 took me "to" ]) %> 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -