<%= h ...%>是什么?在Rails中意味着什么?

问题描述:

我在此处找到了以下语法:

<%=h @person.first_name %>

h 是什么意思?

用于转义标签的输出以避免跨站点脚本编写。在rails 3中,它已更改为字符串的默认值(因此,您不必说逃避此字符串,而是说这是一个安全的字符串)。

It's for escaping the output of the tag to avoid cross-site-scripting. In rails 3, it's been changed to the default for a string (so rather than saying escape this string, you say, this is a safe string).

http://api.rubyonrails.org/classes/ERB/Util.html#method-ch