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

前端 未结 7 1841
一向
一向 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 05:54

    <% %> and <%- and -%> are for any Ruby code, but doesn't output the results (e.g. if statements). the two are the same.

    <%= %> is for outputting the results of Ruby code

    <%# %> is an ERB comment

    Here's a good guide: http://api.rubyonrails.org/classes/ActionView/Base.html

提交回复
热议问题