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

wgf4242 · July 25, 2013 · Last by gaicitadie replied at July 25, 2013 · 2155 hits

在书里没找到详细说明。 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....

Unknow user #4 July 25, 2013

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

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

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

把等号理解成 put、print

You need to Sign in before reply, if you don't have an account, please Sign up first.