What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
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?的更多相关文章
- Ruby on Rails Tutorial读书笔记-1
只是怕忘了命令,全部撸一次,记个大概.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 安装Ruby之前,先要安装RVM: curl -L https://get.rvm.io | bas ...
- Ruby学习笔记4: 动态web app的建立
Ruby学习笔记4: 动态web app的建立 We will first build the Categories page. This page contains topics like Art, ...
- (转)rvm安装与常用命令
rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换. https://rvm.io/ 如果你打算学习ruby/rails, rvm是必不可少的工具之一. 这里所有的命令都是再用户 ...
- 声学感知刻度(mel scale、Bark scale、ERB)与声学特征提取(MFCC、BFCC、GFCC)
梅尔刻度 梅尔刻度(Mel scale)是一种由听众判断不同频率 音高(pitch)彼此相等的感知刻度,表示人耳对等距音高(pitch)变化的感知.mel 刻度和正常频率(Hz)之间的参考点是将1 k ...
- Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)
--reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...
- 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 ...
- [转载]Difference between <context:annotation-config> vs <context:component-scan>
在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...
- 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 ...
- difference between forward and sendredirect
Difference between SendRedirect and forward is one of classical interview questions asked during jav ...
随机推荐
- Phython 学习笔记之——类的初步认识
类是面向对象编程的核心,他扮演相关数据及逻辑容器的角色.他们提供了创建实例对象的蓝图.因为python语言不要求必须以面向对象的方式编程(与JAVA不同),这里简单的举一个例子. 如何定义一个类 cl ...
- SQL Server中数据库文件的存放方式,文件和文件组
原文地址:http://www.cnblogs.com/CareySon/archive/2011/12/26/2301597.html SQL Server中数据库文件的存放方式,文件和文件组 ...
- C#, float.ToString()的一个坑
下面代码的输出竟然是2.0: float a=1.95f;Debug.Log(a.ToString("0.0")); 如果想截取一位小数,可以: float a=1.95f; fl ...
- ant脚本编写
使用ant脚本前的准备 1.下载一个ant安装包.如:apache-ant-1.8.4-bin.zip.解压到E盘. 2.配置环境变量.新增ANT_HOME:E:\apache-ant-1.8.4:P ...
- windows下android环境的搭建:完成后添加android其他版本
JDK: jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe Eclipse:Eclipse3.7.1 Android sdk:android-sd ...
- Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom
一.视图切换类型介绍 在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的. 在iphone中,segue有:push,modal,和cus ...
- 使用maven编译dubbo,导入eclipse(其他maven开源项目编译类似)
dubbo github下载地址:https://github.com/alibaba/dubbo 相关文档:http://dubbo.io/ 使用maven编译dubbo,导入eclipse(其他m ...
- mysql 远程访问授权
给mysql改了密码了,程序就不让登录了: mysql 网外链接 Access denied for user 这不能忍啊!咋办?授权呗! 命令行: GRANT ALL PRIVILEGES ON * ...
- XAMPP 在windows下无法启动Apache解决方案
XAMPP 在windows下无法启动Apache解决方案 一.现象 XAMPP 点击Start Apache时出现如下错误 20:41:12 [Apache] Error: Apache shut ...
- scala vs java 相同点和差异
本贴是我摘抄自国外网站,用作备忘,也作为分享! Similarities between Scala and Java Following are some of the major similari ...