<%,<%=,<%#和-%>之间有什么区别?在ERB中使用Rails吗? [英] What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

查看:62
本文介绍了<%,<%=,<%#和-%>之间有什么区别?在ERB中使用Rails吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您描述一下ERB文件中使用的以下字符的用法:

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

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

每一个的用途是什么?

推荐答案

<% %>

在括号内执行红宝石代码.

Executes the ruby code within the brackets.

<%= %>

将某些内容打印到erb文件中.

Prints something into erb file.

<%== %>

等同于<%=原始%> .逐字打印(即不转义)到erb文件中.(摘自 Ruby on Rails指南.)

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

<% -%>

避免在表达式后换行.

<%# %>

在方括号内注释掉代码;没有发送给客户端(与HTML注释相反).

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

访问 Ruby Doc 了解更多信息关于ERB.

Visit Ruby Doc for more infos about ERB.

这篇关于&lt;%,&lt;%=,&lt;%#和-%&gt;之间有什么区别?在ERB中使用Rails吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆