Thomas Counsell
11/1/2004 9:21:00 AM
Hello
May just have been the way it arrived in my email message, but ruby
code in erb has to be surrounded by <% and %>.
So your sample would need to be:
<html>
<head>
<title> Eruby Example </title>
</head>
<body>
<h1> Enumeration </h1>
<ul>
<% 5.times do |i| %>
<li><%=i%></li>
<% end %>
</ul>
</body>
</html>
Tom
On 1 Nov 2004, at 09:08, Tang Hai Tuan Minh wrote:
>
> Hi all,
>
> This is my first time into the world of Ruby. I was interested in erb
> and so
> I copied part of a code fragment from the PickAxe book (2nd Ed.) into a
> file called sample.html, ran erb over it (erb sample.html), and
> received
> the error message
> "(erb): undefined local variable or method `i' for
> main:Object(NameError)"
>
> The file sample.html is as follows
>
> <html>
> <head>
> <title> Eruby Example </title>
> </head>
> <body>
> <h1> Enumeration </h1>
> <ul>
> %5.times do |i|
> <li><%=i%></li>
> %end
> </ul>
> </body>
> </html>
>
> Now, if I ran erb with erb << ENDRB and write the above code segment
> before
> ENDRB then everything is fine. I had read in the PickAxe book that
> this is
> also similar to what you might get by using irb instead of the ruby
> intepreter. However, the solution of sandwiching the code block between
> begin and end doesn't help in my case.
>
> Can anyone please enlighten me to a solution ? It's kinda late here so
> I am
> too lazy too think.
>
> TIA,
> Minh
>
> --
> Three minutes' thought would suffice to find this out; but thought is
> irksome and three minutes is a long time.
> -- A.E. Houseman
>
>
>