[英]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. 在Ruby on Rails中,我认为helper函数可以帮助转义特殊字符。
Example: " She's the one that took me "to" " 示例:“她是带我去”的那个人”
Code wise: <%= h("She's the one that took me "to" ") %>
明智的代码: <%= 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 我以为h()是html_escape()的别名,它们转换了以下4个字符
< > & "
into 进入
< > & "
Is there something i'm missing with using double quotes? 使用双引号是否缺少我的东西?
Any advice is appreciated Thanks, D 任何建议表示赞赏,谢谢,D
The problem is that your double quote around the word to is closing the double quote opened at the beginning of the string. 问题是您在单词to附近的双引号关闭了在字符串开头打开的双引号。 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" ]) %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.