Escape characters <%= h("") %> and how to deal with double quote in Ruby on Rails
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
< > &开发者_如何转开发amp;amp; "
Is there something i'm missing with using double quotes?
Any advice is appreciated Thanks, D
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" ]) %>
精彩评论