dar*_*eck 1 escaping ruby-on-rails
这可能是一个简单的问题,但我找不到答案.
在Ruby on Rails中,我认为辅助函数可以帮助转义特殊字符.
例如:"她是那个把我带到""的人"
代码明智: <%= h("She's the one that took me "to" ") %>
但是,双引号将不允许我在浏览器上显示代码并给我一个错误.
我认为h()是html_escape()的别名,它们转换以下4个字符
< > & "
Run Code Online (Sandbox Code Playgroud)
成
< > & "
Run Code Online (Sandbox Code Playgroud)
使用双引号有什么我想念的吗?
任何建议表示赞赏谢谢,D
问题是,这个词在你的双引号,以被关闭在字符串的开头开了双引号.试试这个:
<%= h("She's the one that took me \"to\" ") %>
Run Code Online (Sandbox Code Playgroud)
或者,为了避免必须反斜杠内部双引号,您可以使用%语法来创建字符串:
<%= h(%[She's the one that took me "to" ]) %>
Run Code Online (Sandbox Code Playgroud)