<s>
Embedded	B-Application
Ruby	I-Application
(	O
also	O
shortened	O
as	O
ERB	O
)	O
is	O
a	O
templating	B-Application
system	I-Application
that	O
embeds	O
Ruby	B-Language
into	O
a	O
text	O
document	O
.	O
</s>
<s>
It	O
is	O
often	O
used	O
to	O
embed	O
Ruby	B-Language
code	O
in	O
an	O
HTML	B-Language
document	O
,	O
similar	O
to	O
ASP	B-General_Concept
and	O
JSP	B-Language
,	O
and	O
PHP	B-Application
and	O
other	O
server-side	O
scripting	O
languages	O
.	O
</s>
<s>
The	O
templating	B-Application
system	I-Application
of	O
eRuby	B-Application
combines	O
Ruby	B-Language
code	O
and	O
plain	O
text	O
to	O
provide	O
flow	O
control	O
and	O
variable	O
substitution	O
,	O
thus	O
making	O
the	O
combined	O
code	O
easier	O
to	O
maintain	O
.	O
</s>
<s>
The	O
View	O
module	O
of	O
Ruby	B-Application
on	I-Application
Rails	I-Application
is	O
responsible	O
for	O
displaying	O
the	O
response	O
or	O
output	O
on	O
a	O
browser	O
.	O
</s>
<s>
In	O
its	O
simplest	O
form	O
,	O
a	O
view	O
can	O
be	O
a	O
piece	O
of	O
HTML	B-Language
code	I-Language
which	O
has	O
some	O
static	O
content	O
.	O
</s>
<s>
Many	O
Ruby	B-Application
on	I-Application
Rails	I-Application
applications	O
will	O
require	O
dynamic	O
content	O
created	O
by	O
the	O
controller	O
(	O
action	O
method	O
)	O
to	O
be	O
displayed	O
in	O
their	O
view	O
.	O
</s>
<s>
This	O
is	O
made	O
possible	O
by	O
using	O
Embedded	B-Application
Ruby	I-Application
to	O
generate	O
templates	B-Application
which	O
can	O
contain	O
dynamic	O
content	O
.	O
</s>
<s>
Embedded	B-Application
Ruby	I-Application
allows	O
ruby	B-Language
code	O
to	O
be	O
embedded	O
in	O
a	O
view	O
document	O
.	O
</s>
<s>
eRuby	B-Application
allows	O
Ruby	B-Language
code	O
to	O
be	O
embedded	O
within	O
a	O
pair	O
of	O
<% and %>	O
delimiters	B-Algorithm
.	O
</s>
<s>
Apart	O
from	O
creating	O
web	O
pages	O
,	O
eRuby	B-Application
can	O
also	O
be	O
used	O
to	O
create	O
XML	B-Protocol
Documents	I-Protocol
,	O
RSS	O
feeds	O
and	O
other	O
forms	O
of	O
structured	O
text	O
files	O
.	O
</s>
<s>
eRuby	B-Application
dynamically	O
generates	O
static	O
files	O
based	O
on	O
templates	B-Application
.	O
</s>
<s>
These	O
functionalities	O
of	O
eRuby	B-Application
can	O
be	O
found	O
in	O
the	O
ERB	O
Library	O
.	O
</s>
<s>
Different	O
types	O
of	O
tag	B-General_Concept
markers	O
used	O
in	O
ERB	O
templates	B-Application
are	O
:	O
</s>
<s>
:	O
This	O
indicates	O
that	O
the	O
tag	B-General_Concept
encloses	O
an	O
expression	O
.	O
</s>
<s>
Such	O
a	O
tag	B-General_Concept
starts	O
with	O
an	O
opening	O
tag	B-General_Concept
delimiter	B-Algorithm
followed	O
by	O
an	O
equal	O
to	O
symbol	O
and	O
ends	O
with	O
an	O
end	O
tag	B-General_Concept
delimiter	B-Algorithm
.	O
</s>
<s>
During	O
the	O
rendering	O
of	O
the	O
template	B-Application
,	O
this	O
piece	O
of	O
code	O
gets	O
substituted	O
with	O
the	O
result	O
of	O
the	O
code	O
.	O
</s>
<s>
:	O
Code	O
enclosed	O
in	O
such	O
tags	B-General_Concept
is	O
called	O
as	O
a	O
scriptlet	B-Language
.	O
</s>
<s>
The	O
code	O
in	O
such	O
a	O
tag	B-General_Concept
gets	O
executed	O
and	O
its	O
result	O
gets	O
replaced	O
in	O
place	O
of	O
the	O
scriptlet	B-Language
.	O
</s>
<s>
Such	O
tags	B-General_Concept
must	O
have	O
a	O
matching	O
tag	B-General_Concept
to	O
denote	O
the	O
end	O
of	O
a	O
functional	O
block	O
.	O
</s>
<s>
The	O
scriptlet	B-Language
produces	O
no	O
text	O
on	O
its	O
own	O
,	O
it	O
only	O
makes	O
the	O
enclosed	O
statement	O
to	O
run	O
multiple	O
times	O
.	O
</s>
<s>
:	O
Contents	O
of	O
comment	O
tags	B-General_Concept
do	O
n't	O
get	O
rendered	O
in	O
the	O
output	O
.	O
</s>
<s>
Such	O
tags	B-General_Concept
start	O
with	O
an	O
open	O
tag	B-General_Concept
delimiter	B-Algorithm
followed	O
by	O
a	O
hash	O
symbol	O
and	O
end	O
with	O
an	O
end	O
tag	B-General_Concept
delimiter	B-Algorithm
.	O
</s>
<s>
Example	O
of	O
a	O
comment	O
tag	B-General_Concept
is	O
shown	O
below	O
:	O
</s>
<s>
This	O
is	O
the	O
same	O
as	O
a	O
comment	O
in	O
Ruby	B-Language
.	O
</s>
<s>
All	O
Ruby	B-Language
code	O
after	O
the	O
#	O
is	O
ignored	O
and	O
generates	O
nothing	O
.	O
</s>
<s>
Other	O
things	O
common	O
in	O
eRuby	B-Application
are	O
simply	O
common	O
in	O
Ruby	B-Language
,	O
such	O
as	O
string	O
substitution	O
with	O
#{string_name},	O
which	O
is	O
similar	O
in	O
languages	O
such	O
as	O
Perl	B-Language
or	O
PHP	B-Application
.	O
</s>
<s>
Newlines	O
in	O
eRuby	B-Application
can	O
be	O
suppressed	O
by	O
adding	O
a	O
hyphen	O
at	O
the	O
beginning	O
of	O
the	O
end	O
tag	B-General_Concept
delimiter	B-Algorithm
.	O
</s>
<s>
There	O
are	O
several	O
implementations	O
of	O
eRuby	B-Application
,	O
namely	O
:	O
</s>
<s>
erb	O
is	O
an	O
implementation	O
of	O
eRuby	B-Application
written	O
purely	O
in	O
the	O
Ruby	B-Language
programming	I-Language
language	I-Language
and	O
included	O
in	O
the	O
.	O
</s>
<s>
A	O
template	B-Application
can	O
be	O
generated	O
by	O
running	O
a	O
piece	O
of	O
code	O
written	O
using	O
the	O
object	O
.	O
</s>
<s>
The	O
same	O
could	O
be	O
achieved	O
using	O
the	O
below	O
code	O
which	O
does	O
not	O
make	O
use	O
of	O
an	O
ERB	O
object:Both	O
of	O
the	O
above	O
code	B-Application
snippets	I-Application
generate	O
the	O
same	O
output	O
.	O
</s>
<s>
But	O
what	O
happens	O
when	O
we	O
interchange	O
lines	O
2	O
with	O
line	O
3	O
in	O
the	O
first	O
code	B-Application
snippet	I-Application
and	O
line	O
1	O
with	O
line	O
2	O
in	O
the	O
second	O
code	B-Application
snippet	I-Application
?	O
</s>
<s>
The	O
first	O
snippet	B-Application
changes	O
to	O
the	O
code	O
shown	O
below	O
:	O
</s>
<s>
The	O
second	O
code	B-Application
snippet	I-Application
changes	O
to	O
the	O
below	O
code:The	O
above	O
code	O
will	O
not	O
get	O
executed	O
.	O
</s>
<s>
Thus	O
,	O
the	O
main	O
reason	O
of	O
using	O
an	O
ERB	O
object	O
is	O
to	O
write	O
templates	B-Application
ahead	O
of	O
time	O
,	O
by	O
binding	O
variables	O
and	O
methods	O
which	O
may	O
not	O
exist	O
at	O
the	O
given	O
time	O
.	O
</s>
<s>
The	O
template	B-Application
gets	O
processed	O
only	O
when	O
result	O
is	O
called	O
on	O
the	O
ERB	O
object	O
.	O
</s>
<s>
In	O
order	O
to	O
get	O
access	O
to	O
instance	B-Language
methods	I-Language
and	O
instance	B-Application
variable	I-Application
of	O
an	O
object	O
,	O
ERB	O
makes	O
use	O
of	O
a	O
binding	O
object	O
.	O
</s>
<s>
Access	O
to	O
variables	O
and	O
methods	O
of	O
an	O
object	O
is	O
given	O
by	O
the	O
private	O
binding	O
object	O
which	O
exists	O
in	O
each	O
ruby	B-Language
class	O
.	O
</s>
<s>
By	O
giving	O
a	O
number	O
in	O
the	O
second	O
parameter	O
(	O
max	O
value	O
=	O
4	O
)	O
one	O
can	O
make	O
the	O
template	B-Application
run	O
in	O
a	O
different	O
thread	B-Operating_System
.	O
</s>
<s>
ERB	O
has	O
many	O
other	O
methods	O
exposed	O
which	O
can	O
be	O
used	O
to	O
render	O
a	O
template	B-Application
.	O
</s>
<s>
As	O
it	O
has	O
been	O
already	O
explained	O
in	O
the	O
previous	O
sections	O
,	O
the	O
erb	O
is	O
used	O
to	O
generate	O
templates	B-Application
.	O
</s>
<s>
To	O
achieve	O
this	O
,	O
we	O
can	O
use	O
the	O
redirection	O
ability	O
provided	O
in	O
the	O
command-line	B-Application
and	O
redirect	O
the	O
output	O
to	O
a	O
file	O
rather	O
than	O
making	O
it	O
print	O
on	O
the	O
standard	O
output	O
.	O
</s>
<s>
In	O
the	O
above	O
example	O
,	O
output	O
gets	O
redirected	O
to	O
my_view.html.erb	O
file	O
.	O
</s>
<s>
To	O
remember	O
this	O
functionality	O
,	O
one	O
can	O
remember	O
the	O
Ruby	B-Language
key	O
word	O
require	O
,	O
which	O
does	O
the	O
same	O
functionality	O
as	O
the	O
-r	O
option	O
.	O
</s>
<s>
erubis	O
is	O
an	O
implementation	O
of	O
eRuby	B-Application
implemented	O
in	O
Ruby	B-Language
and	O
also	O
in	O
Java	B-Language
.	O
</s>
<s>
According	O
to	O
its	O
home	O
page	O
,	O
it	O
runs	O
faster	O
than	O
eRuby	B-Application
and	O
ERb	O
and	O
has	O
several	O
useful	O
options	O
,	O
including	O
alternate	O
tags	B-General_Concept
allowing	O
for	O
valid	O
XML	B-Protocol
.	O
</s>
<s>
ember	O
is	O
a	O
pure	O
Ruby	B-Language
implementation	O
of	O
eRuby	B-Application
for	O
Linux	B-Application
.	O
</s>
<s>
It	O
allows	O
debugging	O
of	O
eRuby	B-Application
templates	B-Application
,	O
improves	O
their	O
composability	O
,	O
and	O
provides	O
powerful	O
shorthand	O
eRuby	B-Application
directives	O
.	O
</s>
<s>
Simple	O
expression	O
tagxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
can	O
be	O
written	O
as	O
%xy	O
.	O
</s>
<s>
,	O
can	O
change	O
tag	B-General_Concept
pattern	O
to	O
anything	O
.	O
</s>
<s>
as	O
one	O
can	O
change	O
tag	B-General_Concept
patterns	O
.	O
</s>
<s>
,	O
<%xy%> can be written as %xy.The content of the tag is evaluated as an eRuby template.The content of the tag is evaluated as Ruby code and is expected to be a path pointing to a Ruby template file which is read, evaluated, and rendered.Same as <%+ %>	O
but	O
file	O
contents	O
are	O
simply	O
rendered	O
into	O
the	O
output.Treats	O
the	O
enclosed	O
code	O
as	O
a	O
block	O
of	O
Ruby	B-Language
code	O
and	O
(	O
if	O
necessary	O
)	O
appends	O
a	O
do	O
keyword	O
to	O
the	O
body	O
of	O
the	O
tag	B-General_Concept
.	O
</s>
