What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

前端 未结 7 1621
一向
一向 2020-11-21 05:33

Can some one please describe the usage of the following characters which is used in ERB file:

<%   %>
<%=  %>
<%  -%>
<%#  %>
         


        
7条回答
  •  无人共我
    2020-11-21 06:05

    <% %>
    

    Executes the ruby code within the brackets.

    <%= %>
    

    Prints something into erb file.

    <%== %>
    

    Equivalent to <%= raw %>. Prints something verbatim (i.e. w/o escaping) into erb file. (Taken from Ruby on Rails Guides.)

    <% -%>
    

    Avoids line break after expression.

    <%# %>
    

    Comments out code within brackets; not sent to client (as opposed to HTML comments).

    Visit Ruby Doc for more infos about ERB.

提交回复
热议问题