http://stackoverflow.com/questions/998979/difference-between-and-in-rails/25617607#25617607

http://stackoverflow.com/questions/7996695/what-is-the-difference-between-and-in-erb-in-rails

<% %>

Executes the ruby code within the brackets.

<%= %>

Prints something into erb file.

<% -%>

Avoids line break after expression.

<%# %>

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

In Ruby 2.1 (not necessarily with Rails), the - removes one trailing newline:

  • the newline must be the first char after the >
  • no spaces are removed
  • only a single newline is removed
  • you must pass the '-' option to use it

Examples:

require 'erb'
ERB.new("<%= 'a' %>\nb").result == "a\nb" or raise
begin ERB.new("<%= 'a' -%>\nb").result; rescue SyntaxError ; else raise; end
ERB.new("<%= 'a' %>\nb" , nil, '-').result == "a\nb" or raise
ERB.new("<%= 'a' -%>\nb" , nil, '-').result == 'ab' or raise
ERB.new("<%= 'a' -%> \nb" , nil, '-').result == "a \nb" or raise
ERB.new("<%= 'a' -%>\n b" , nil, '-').result == 'a b' or raise
ERB.new("<%= 'a' -%>\n\nb", nil, '-').result == "a\nb" or raise

What is the difference between <%, <%=, <%# and -%> in ERB in Rails?的更多相关文章

  1. Ruby on Rails Tutorial读书笔记-1

    只是怕忘了命令,全部撸一次,记个大概.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 安装Ruby之前,先要安装RVM: curl -L https://get.rvm.io | bas ...

  2. Ruby学习笔记4: 动态web app的建立

    Ruby学习笔记4: 动态web app的建立 We will first build the Categories page. This page contains topics like Art, ...

  3. (转)rvm安装与常用命令

    rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换. https://rvm.io/ 如果你打算学习ruby/rails, rvm是必不可少的工具之一. 这里所有的命令都是再用户 ...

  4. 声学感知刻度(mel scale、Bark scale、ERB)与声学特征提取(MFCC、BFCC、GFCC)

    梅尔刻度 梅尔刻度(Mel scale)是一种由听众判断不同频率 音高(pitch)彼此相等的感知刻度,表示人耳对等距音高(pitch)变化的感知.mel 刻度和正常频率(Hz)之间的参考点是将1 k ...

  5. Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)

    --reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...

  6. What's the difference between a stub and mock?

    I believe the biggest distinction is that a stub you have already written with predetermined behavio ...

  7. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  8. What's the difference between <b> and <strong>, <i> and <em> in HTML/XHTML? When should you use each?

    ref:http://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em The ...

  9. difference between forward and sendredirect

    Difference between SendRedirect and forward is one of classical interview questions asked during jav ...

随机推荐

  1. pip使用报错【cannot import name HTTPSHandler】

    python2.7,报错如下: Traceback (most recent call last): File "/usr/local/bin/pip", line 9, in & ...

  2. 1.Nexus安装与配置

    1.Nexus下载下载地址:http://www.sonatype.org/nexus/go/下载后的文件:nexus-2.11.4-01-bundle.zip安装:直接解压到某个目录即可解压后,会有 ...

  3. 在VS 2015 RTM 版中 提示 未能正确加载 NuGetPackage包

      在原来的项目中曾经启用了Nuget在编译时还原包功能.这样就会在 *.sln在平行目录生成 一个.Nuget文件夹, 删除了它,就好了.   我分析原因是, VS 2015 使用的是 NugetP ...

  4. CSS之background属性

    css背景是个很有意思的东西,可设置 背景色:background-color 背景图:backgoround-image 背景图显示相对位置:background-position,正数图片往右下移 ...

  5. Android视录视频示例

    这几天需要搞一个Android视频通话功能,从最简单的视频录制开始,网上例子大多不完整.下面的示例参考过别人的代码,还是拿出来给需要的朋友分享下. Activity类:VideoActivity pa ...

  6. shiro权限验证标签

    实例: spring-shiro.xml /admin/repairType/index = roles["ROLE_ADMIN"] /admin/user=roles[" ...

  7. Linux 环境下开机自启动Oracle服务

    使用如下命令查看Oracle相关服务是否已启动: ps aux | grep ora_ #若无ora_**_**相关的进程,则oracle数据库实例未启动 netstat -tlnup | grep ...

  8. mongodb不同版本之间有很大的差异

    今天主要说下我为了给mongodb数据库添加authorization,大家应该知道,mongo默认是无auth运行的.这可能是方便小伙伴学习命令吧. 由于之前发布的一个项目,在亚马逊的云上,处于内部 ...

  9. 【性能测试】性能测试总结<一>

    目录: 一. 什么是软件性能 二.不同群体眼中的性能 三.性能测试类型 四.性能测试应用场景 五.性能测试基本概念 正文: 一. 什么是软件性能 定义:软件的性能是软件的一种非功能特性,它关注的不是软 ...

  10. Async 和 Await的性能(.NET4.5新异步编程模型)

    异步编程长时间以来一直都是那些技能高超.喜欢挑战自我的开发人员涉足的领域 — 这些人愿意花费时间,充满热情并拥有心理承受能力,能够在非线性的控制流程中不断地琢磨回调,之后再回调. 随着 Microso ...