新手问题 <% 和 <%= 的区别,这属于哪部分内容,怎样在 Google 搜索?

wgf4242 · 2013年07月25日 · 最后由 gaicitadie 回复于 2013年07月25日 · 2155 次阅读

在书里没找到详细说明。 google 里貌似也没法搜索。

eRuby means "embedded Ruby" in documents. Embedded patterns are '<% statement %>' and '<%= expression %>'. The following is an example of eRuby. '<% ... %>' means Ruby statement and '<%= ... %>' means Ruby expression.

<% 较多的用于逻辑,大多不做页面显示,<%= 都用于页面显示元素,如:

<% if @comments.blank? %>
    <p>暂时还没有评论喔</p>
<% else %>
    <% @comments.each do |comment| %>
        <div class="comment">
            <p><%= comment.content %></p>
        </div>
    <% end %>
<% end %>

乱举的一个例子,也不知道恰当不恰当。

或者简单来说?
<%= 是会输出内容到页面的,比如 form_for 会生成一个 form <% 用于不会向页面输出内容的语句,比如 if else for....

匿名 #4 2013年07月25日

用过 php 没,类似于 <?=<?php 的区别。

<% 内代码只执行 <%= 内代码执行后结果会 put

搜索符号不用 google 用这个 http://www.symbolhound.com/ 今天新学的姿势

把等号理解成 put、print

需要 登录 后方可回复, 如果你还没有账号请 注册新账号