What is the meaning of “h” in “<%=h [ …] %>”?

前端 未结 6 1816
故里飘歌
故里飘歌 2020-12-24 05:00

When I generate a default scaffold, the display tags on show.html.erb have

<%=h @broker.name %>

I know the difference between &

6条回答
  •  眼角桃花
    2020-12-24 05:28

    <%=h is actually 2 things happening. You're opening an erb tag (<%=) and calling the Rails method h to escape all symbols.

    These two calls are equivalent:

    <%=h person.first_name %>
    <%= h(person.first_name) %>
    

    The h method is commonly used to escape HTML and Javascript from user-input forms.

提交回复
热议问题